'Write all data in this buffer, starting at stream position 0, formatted
in hashed blocks to the given `stream`.
For example, writing data from one file into another as hashed blocks::
# create new hashed block io without input stream or data
hb = HashedBlockIO()
# read from a file, write into the empty hb
with open(\'sample.dat\', \'rb\') as infile:
hb.write(infile.read())
# write from the hb into a new file
with open(\'hb_sample.dat\', \'w\') as outfile:
hb.write_block_stream(outfile)'

def write_block_stream(self, stream, block_length=BLOCK_LENGTH):

    if (not (isinstance(stream, io.IOBase) or isinstance(stream, file))):
        raise TypeError('Stream    does    not    have    the    buffer    interface.')
    index = 0
    self.seek(0)
    while True:
        data = self.read(block_length)
        if data:
            stream.write(struct.pack('<I', index))
            stream.write(hashlib.sha256(data).digest())
            stream.write(struct.pack('<I', len(data)))
            stream.write(data)
            index += 1
        else:
            stream.write(struct.pack('<I', index))
            stream.write(('\x00' * 32))
            stream.write(struct.pack('<I', 0))
            break
