# aligned-block-file

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

Latest version **1.2.2** (published 2019-05-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install aligned-block-file
pnpm add aligned-block-file
yarn add aligned-block-file
bun add aligned-block-file
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.2 |
| Published | 2019-05-20 |
| First published | 2016-11-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 28.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | 'Dominic Tarr' |
| Maintainers | arj03, christianbundy, dominictarr, regular |

## Links

- npm: https://www.npmjs.com/package/aligned-block-file
- Repository: https://github.com/flumedb/aligned-block-file
- Issues: https://github.com/flumedb/aligned-block-file/issues
- npm.io page: https://npm.io/package/aligned-block-file

## Dependencies (6)

- [obv](https://npm.io/package/obv.md) ^0.0.1
- [int53](https://npm.io/package/int53.md) ^1.0.0
- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.1
- [rwlock](https://npm.io/package/rwlock.md) ^5.0.0
- [hashlru](https://npm.io/package/hashlru.md) ^2.1.0
- [uint48be](https://npm.io/package/uint48be.md) ^2.0.1

## Recent versions

- 1.2.2 (latest) — 2019-05-20
- 1.2.1 — 2019-05-14
- 1.2.0 — 2019-03-28
- 1.1.5 — 2019-02-07
- 1.1.4 — 2018-11-08
- 1.1.3 — 2018-06-11
- 1.1.2 — 2017-09-12
- 1.1.1 — 2017-07-18
- 1.1.0 — 2017-07-06
- 1.0.0 — 2017-05-19
- 0.1.4 — 2017-05-16
- 0.1.3 — 2017-04-15
- 0.1.2 — 2017-04-15
- 0.1.1 — 2016-12-28
- 0.0.1 — 2016-11-08
- … 1 more at https://npm.io/package/aligned-block-file/versions

## README

# aligned-block-file

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 [fs.open](http://devdocs.io/node/fs#fs_fs_open_path_flags_mode_callback)

### abf.read(start, 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)

### abf.readUInt48BE (start, cb)

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

### abf.readUInt64BE (start, cb)

read a UInt64BE from the file, since javascript numbers are restricted to double
this will only set the first 53 bits. Take care with your 53 bit int! if you use bitwise
operations it will collapse back to 32 bit, you need to use `*2` instead of `<< 1`, etc.
(`cb` may be sync, if the buffer is already in cache)

### abf.size

an observable of the files size.

### abf.offset

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.

### truncate(length, cb)

shorten the file to `length` removing anything after that point.

## License

MIT

---
_Source: https://npm.io/package/aligned-block-file · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
