@mediafish/amf0

0.0.5 • Public • Published

Build Status Coverage Status Dependency Status Development Dependency Status Known Vulnerabilities npm Downloads XO code style

amf0

A library to read/write AMF0 binary format

Install

NPM

Usage

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

Readme

Keywords

Package Sidebar

Install

npm i @mediafish/amf0

Weekly Downloads

5

Version

0.0.5

License

MIT

Unpacked Size

12.9 kB

Total Files

4

Last publish

Collaborators

  • kuu