# buffer-write

> Write to a buffer without maintaining an offset or knowing its length

Latest version **0.0.2** (published 2014-06-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install buffer-write
pnpm add buffer-write
yarn add buffer-write
bun add buffer-write
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2014-06-19 |
| First published | 2014-06-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | hypergeometric |

## Links

- npm: https://www.npmjs.com/package/buffer-write
- Repository: https://github.com/coinative/buffer-write
- Issues: https://github.com/coinative/buffer-write/issues
- npm.io page: https://npm.io/package/buffer-write

## Recent versions

- 0.0.2 (latest) — 2014-06-19

## README

# buffer-write

[![Build Status](https://img.shields.io/travis/coinative/buffer-write.svg)](https://travis-ci.org/coinative/buffer-write) [![Coverage Status](https://img.shields.io/coveralls/coinative/buffer-write.svg)](https://coveralls.io/r/coinative/buffer-write?branch=master)

Write to a buffer without maintaining an offset or knowing its length.

* This module tries to mirror Buffer methods for simplicity.
* Supports writing 64-bit values at 52-bit precision (JavaScript safe integer maximum).

## Install

```
npm install buffer-write
```

## Usage

```js
var Writer = require('buffer-write');

// Normal method
var writer = new Writer()
writer.write('a')
writer.fill(1, 3)
writer.writeInt8(0x72)
writer.toBuffer(); // <Buffer 61 01 01 01 72>

// Chain method
Writer()
  .writeUInt16BE(0x7623)
  .write(new Buffer([1, 2, 3, 4]), 2)
  .writeUInt16LE(0x1800)
  .toBuffer(); // <Buffer 76 23 01 02 00 18>
```

## API

NOTE: There is no concept of offset when using this module as values are effectively appended to each other.

### write[U]Int8(value), write[U]{16,32,64}{BE,LE}(value)

Write an integer of the specified size and endian format. A RangeError will be thrown for any out of range values. 64-bit integer methods will only accept 52-bit integer values.

### writeFloat{BE,LE}(value), writeDouble{BE,LE}(value)

Write a floating point number of the specified size and endian format.

### write(string, [length], [encoding])

Write a string of specified length and encoding.

### write(buffer, [start], [end])

Write a buffer or part of a buffer.

### fill(value, length)

Fill with length repetitions of the specified value.

### length

The number of bytes currently written.

### copy(targetBuffer, [targetStart], [sourceStart], [sourceEnd])

Write our values into an existing buffer.

### toBuffer()

Create a new buffer and write our values.

## License

MIT

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