3.2.1-a • Published 4 years ago
@truelossless/bytearray-node v3.2.1-a
Important notice
This is a fork of Zaseth's node-bytearray
Updated to support naïve buffer overflows (as used in some AS games)
It is mainly for personnal purposes and it won't probably be updated: you should use the original node-bytearray instead, which still receives updates.
ByteArray-node
A Node.js implementation of the Actionscript 3 ByteArray supporting AMF0/AMF3.
Installation
npm install bytearray-node
API (please see this)
A simple example
const ByteArray = require('bytearray-node')
const ba = new ByteArray()
ba.writeByte(1)
ba.writeShort(5)
ba.position = 0
console.log(ba.readByte()) // 1
console.log(ba.readShort()) // 5
AMF3 IExternalizable example
const ByteArray = require('bytearray-node')
const IExternalizable = require('bytearray-node/enums/IExternalizable')
class Person extends IExternalizable {
constructor(name, age) {
super()
this.name = name
this.age = age
}
writeExternal(ba) {
ba.writeUTF(this.name)
ba.writeByte(this.age)
}
readExternal(ba) {
this.name = ba.readUTF()
this.age = ba.readByte()
}
}
ByteArray.registerClassAlias('src.person', Person)
const ba = new ByteArray()
ba.writeObject(new Person('Daan', 18))
ba.position = 0
console.log(ba.readObject()) // Person { name: 'Daan', age: 18 }