def read_chunks(fd, chunk_size=None):
    """Read chunks from a file descriptor"""
    if chunk_size is None:
        import resource
        chunk_size = resource.getpagesize()
    while True:
        data = fd.read(chunk_size)
        if not data:
            break
        yield data
