0.0.5 • Published 1 year ago

@mediafish/amf0 v0.0.5

Weekly downloads
13
License
MIT
Repository
github
Last release
1 year ago

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

NameTypeRequiredDefaultDescription
bufferBufferYesN/AThe buffer from which the data is read
offsetnumberYesN/AAn 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

NameTypeRequiredDefaultDescription
bufferBufferYesN/AThe buffer to which the data is written
offsetnumberYesN/AAn integer to specify the position within the buffer
valueanyYesN/AThe data to be written to the buffer

return value

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

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago