# @mediafish/amf0

> A library to read/write AMF0 binary format

Latest version **0.0.5** (published 2022-12-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install @mediafish/amf0
pnpm add @mediafish/amf0
yarn add @mediafish/amf0
bun add @mediafish/amf0
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2022-12-04 |
| First published | 2020-05-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 12.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Kuu Miyazaki |
| Maintainers | kuu |
| Keywords | Adobe, AMF0 |

## Links

- npm: https://www.npmjs.com/package/@mediafish/amf0
- Repository: https://github.com/media-fish/amf0
- Homepage: https://github.com/media-fish/amf0#readme
- Issues: https://github.com/media-fish/amf0/issues
- npm.io page: https://npm.io/package/@mediafish/amf0

## Dependencies (1)

- [@mediafish/buffer-operator](https://npm.io/package/@mediafish/buffer-operator.md) ^0.1.2

## Recent versions

- 0.0.5 (latest) — 2022-12-04
- 0.0.4 — 2022-12-03
- 0.0.3 — 2020-08-02
- 0.0.2 — 2020-05-03
- 0.0.1 — 2020-05-02

## README

[![Build Status](https://travis-ci.org/media-fish/amf0.svg?branch=master)](https://travis-ci.org/media-fish/amf0)
[![Coverage Status](https://coveralls.io/repos/github/media-fish/amf0/badge.svg?branch=master)](https://coveralls.io/github/media-fish/amf0?branch=master)
[![Dependency Status](https://david-dm.org/media-fish/amf0.svg)](https://david-dm.org/media-fish/amf0)
[![Development Dependency Status](https://david-dm.org/media-fish/amf0/dev-status.svg)](https://david-dm.org/media-fish/amf0#info=devDependencies)
[![Known Vulnerabilities](https://snyk.io/test/github/media-fish/amf0/badge.svg)](https://snyk.io/test/github/media-fish/amf0)
[![npm Downloads](https://img.shields.io/npm/dw/@mediafish/amf0.svg?style=flat-square)](https://npmjs.com/@mediafish/amf0)
[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)

# amf0

A library to read/write AMF0 binary format

## Install
[![NPM](https://nodei.co/npm/@mediafish/amf0.png?mini=true)](https://nodei.co/npm/@mediafish/amf0/)

## Usage

```js
const {readValue, writeValue} = require('@mediafish/amf0');


const buffer = Buffer.from([0xFF, 0xFF, 0xFF, 0x61, 0x62, 0x63]);

// Read AMF0
let offset, value, array = [];
while(offset < buffer.length) {
  [offset, value] = readValue(buffer, offset);
  console.log(JSON.stringify(value, null, 4);
  array.push(value);
}

// Write AMF0
offset = 0;
for (const item of array) {
  // First, pass null instead of a buffer to detect how many bytes are needed
  offset = writeValue(null, offset, item);
}

// And then alloc a buff
const dest = Buffer.alloc(offset);
for (const item of array) {
  // Write data actually to the buffer
  offset = writeValue(dest, offset, item);
}

```

## API

### `readValue(buffer, offset)`
Read data from the buffer

#### params
| Name     | Type    | Required | Default | Description   |
| -------- | ------- | -------- | ------- | ------------- |
| `buffer` | `Buffer` | Yes | N/A | The buffer from which the data is read |
| `offset` | number  | Yes      | N/A     | An integer to specify the position within the buffer |

#### return value
An array containing the following pair of values
| Index | Type   | Description  |
| ----- | ------ | ------------ |
| [0]   | number | An integer to indicate the position from which the next data should be read |
| [1]   | any | The read value |

### `writeValue(buffer, offset, value)`
Write data to the buffer

#### params
| Name     | Type    | Required | Default | Description   |
| -------- | ------- | -------- | ------- | ------------- |
| `buffer` | `Buffer` | Yes | N/A | The buffer to which the data is written |
| `offset` | number  | Yes      | N/A     | An integer to specify the position within the buffer |
| `value`  | any  | Yes      | N/A     | The data to be written to the buffer |

#### return value
An integer to indicate the position from which the next data should be read

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