git ssb


Dominic / block-reader


Dominic Tarr committed 0.1.0Latest: e5f9a47 on 12/26/2016, 4:59:52 PM


read and write to a file in a cache-friendly way by using aligned blocks.

This module provides an interface to read arbitary buffers from a file, and manages it as a series of aligned buffers. This allows you to write high performance binary file formats, where many reads do not necessarily mean many fs reads.

Blocks(filename, block_size, flags) => AlignedBlockFile

create an instance, block_size is the size of the underlying block. I suggest 1024 or 4096 or some multiple of your OS block size. flags is passed to, end, cb)

read a buffer from the file. If the range is already in the cache cb will be called synchronously.

abf.readUInt32BE (start, cb)

read a UInt32BE from the file. (cb may be sync, if the buffer is already in cache)


an observable of the files size.


an observable of the end of the file

append (buf, cb)

append buf to the file.

this must not be called again until the previous call has returned. updated values for size and offset will be triggered immediately before the cb is called.



Built with git-ssb-web