https://github.com/heapwolf/skipfile
Append data, seek forward and seek backward inside a binary file.
https://github.com/heapwolf/skipfile
Last synced: 8 months ago
JSON representation
Append data, seek forward and seek backward inside a binary file.
- Host: GitHub
- URL: https://github.com/heapwolf/skipfile
- Owner: heapwolf
- Created: 2014-08-08T23:13:15.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2018-12-22T15:06:41.000Z (about 7 years ago)
- Last Synced: 2024-04-14T22:13:32.144Z (over 1 year ago)
- Language: JavaScript
- Size: 27.3 KB
- Stars: 10
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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.
```js
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.
```js
const { err, bytesWritten } = await handle.append(Buffer.from('Hello, world'))
```
### async next(bytes)
Iterate forward.
```js
while (true) {
const { err, buffer, index } = await handle.next()
if (err || !buffer) {
break
}
console.log(buffer.toString())
}
```
### async seek(index)
TODO
```js
const { err, buffer } = await handle.seek(index)
```
### async close()
Closes the file descriptor opened by the constructor.
```javascript
await skip.close()
```
## INSTANCE MEMBERS
### size
Tracks the size of the file opened by the constructor.