diff --git a/README.md b/README.md index 4ace917..3314c15 100644 --- a/README.md +++ b/README.md @@ -136,11 +136,11 @@ class Protocol { ### ๐Ÿ” Reading an ArrayBuffer into Objects ```typescript -import { binread, BinaryReader } from 'binspector' +import { binread } from 'binspector' const buf = new Uint8Array([0x02, 0x01, 0x02, 0x03, 0x04]) -binread(new BinaryReader(buf), Protocol) +binread(buf, Protocol) // => { len: 2, coords: [{ x: 1, y: 2 }, { x: 3, y: 4 }] } ``` @@ -151,7 +151,7 @@ import { binwrite, BinaryWriter } from 'binspector' const obj = { len: 2, coords: [{ x: 1, y: 2 }, { x: 3, y: 4 }] } -binwrite(new BinaryWriter(), Protocol, obj).buffer() +binwrite(obj, Protocol) // => [0x02, 0x01, 0x02, 0x03, 0x04] ``` diff --git a/docs/Getting-Started-With-Binspector.md b/docs/Getting-Started-With-Binspector.md index f372cf4..5364e74 100644 --- a/docs/Getting-Started-With-Binspector.md +++ b/docs/Getting-Started-With-Binspector.md @@ -93,7 +93,7 @@ import * as fs from 'node:fs' import * as path from 'node:path' const data = fs.readFileSync(path.join(import.meta.dirname, 'file.bin')) -const protocol = binread(new BinaryReader(data), Protocol) +const protocol = binread(data, Protocol) ``` From an high level point of view the `binread` function will first check @@ -165,9 +165,9 @@ const obj = { bar: 0x01 } -const protocol = binwrite(new BinaryWriter(), obj, Protocol) +const protocol = binwrite(obj, Protocol) -const buf = protocol.buffer() // <= ArrayBuffer(...) +const buf = protocol.buffer // <= ArrayBuffer(...) await fs.appendFile(path.join(__dirname, 'proto.bin'), new Uint8Array(buf)); ``` @@ -196,3 +196,51 @@ flowchart TB end PostOperation --> A@{ shape: framed-circle, label: "Stop" } ``` + +### ๐ŸŒ Using Binspector in the browser + +Considering the following tag in the webpage. + +```html + + + +