8000 GitHub - heapwolf/skipfile: Append data, seek forward and seek backward inside a binary file.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Append data, seek forward and seek backward inside a binary file.

Notifications You must be signed in to change notification settings

heapwolf/skipfile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SYNOPSIS

Append only binary data file store.

FORMAT

Each block consists of a sequence (index), a length (length) and a chunk of variable length of data. Because of this, only the sequence and length need to be read, making it possible to "skip" through the file to find a specific sequence. Both sequence and length are encoded as varints.

[SEQUENCE][LENGTH][DATA...]...

API

CONSTRUCTOR

The constructor accepts an options object. { filename: path } specifies the target file to read and write to.

const { err, handle } = await new Skipfile()

INSTANCE METHODS

Instance methods do not throw, they return an object which may contain { err }.

async append(value)

Appends a value to the file specified in the constructor.

const { err, bytesWritten } = await handle.append(Buffer.from('Hello, world'))

async next(bytes)

Iterate forward.

while (true) {
  const { err, buffer, index } = await handle.next()

  if (err || !buffer) {
    break
  }

  console.log(buffer.toString())
}

async seek(index)

TODO

const { err, buffer } = await handle.seek(index)

async close()

Closes the file descriptor opened by the constructor.

await skip.close()

INSTANCE MEMBERS

size

Tracks the size of the file opened by the constructor.

About

Append data, seek forward and seek backward inside a binary file.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0