New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

divine-binary-object

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

divine-binary-object

A TypeScript library working with binary data.

latest
Source
npmnpm
Version
0.1.6
Version published
Maintainers
1
Created
Source

Divine Binary Object

An easy way to store objects that contain binary data in JavaScript.

You can use typed objects to make sure that a value gets stored as a certian type.

Otherwise you can just make a normal JavaScript object with TypedArrays.

import { DBO } from "divine-binary-object";

/*
 Normal Object mode
*/
(() => {
  const buf = DBO.objectToBuffer({
    v0: [
      {
        v0: new Uint8ClampedArray([1, 2, 3, 4]),
      },
      {
        v0: new Uint16Array([1, 2, 3, 4]),
      },
    ],
    v1: 12.12,
    v2: DBO.nodes._16ui(1212),
    v3: "value 3",
    v4: [1, 2, 3, 4, 5, 6, 7, 8],
    v5: ["hello", "sup"],
    v6: {
      hello: "sup",
    },
  });
  console.log("[OBJECT MODE]");
  console.log(buf);
  const obj = DBO.bufferToObject<any>(buf);
  console.log(obj);
})();

const TNM = DBO.nodes;
/*
 Typed Node Mode
*/
(() => {
  const mmdData = TNM.object({
    v0: TNM.array([
      TNM.object({
        v0: TNM.typedArray("8uic", [1, 2, 3, 4]),
      }),
      TNM.object({
        v0: TNM.typedArray("16ui", [1, 2, 3, 4]),
      }),
    ]),
    v1: TNM._32f(12.12),
    v2: TNM._16ui(1212),
    v3: TNM.string("value 3"),
    v4: TNM.typedArray("16ui", [1, 2, 3, 4, 5, 6, 7, 8]),
    v5: TNM.stringArray(["hello", "sup"]),
    v6: TNM.json({
      hello: "sup",
    }),
  });
  console.log("[TYPED NODE MODE]");
  const buffer = DBO.toBuffer(mmdData);
  console.log(buffer);
  const object = DBO.bufferToObject(buffer);
  console.log(object);
})();
[OBJECT MODE]
ArrayBuffer {
  [Uint8Contents]: <00 03 08 02 00 76 00 30 06 03 08 02 00 76 00 30 19 0b 00 00 00 04 01 02 03 04 04 03 08 02 00 76 00 30 19 0d 00 00 00 04
00 01 00 02 00 03 00 04 04 07 08 02 00 76 00 31 11 40 28 3d 70 a3 d7 0a 3d 08 02 00 76 00 32 0d 04 bc 08 02 00 76 00 33 16 00 00 00 07 00 76 00 61 00 6c 00 75 00 65 00 20 00 33 08 ... 146 more bytes>,
  byteLength: 246
}
{
  v0: [ { v0: [Uint8ClampedArray] }, { v0: [Uint16Array] } ],
  v1: 12.12,
  v2: 1212,
  v3: 'value 3',
  v4: [
    1, 2, 3, 4,
    5, 6, 7, 8
  ],
  v5: [ 'hello', 'sup' ],
  v6: { hello: 'sup' }
}
[TYPED NODE MODE]
ArrayBuffer {
  [Uint8Contents]: <00 03 08 02 00 76 00 30 06 03 08 02 00 76 00 30 19 0b 00 00 00 04 01 02 03 04 04 03 08 02 00 76 00 30 19 0d 00 00 00 04
00 01 00 02 00 03 00 04 04 07 08 02 00 76 00 31 0e 41 41 eb 85 08 02 00 76 00 32 0d 04 bc 08 02 00 76 00 33 16 00 00 00 07 00 76 00 61 00 6c 00 75 00 65 00 20 00 33 08 02 00 76 00 ... 101 more bytes>,
  byteLength: 201
}
{
  v0: [ { v0: [Uint8ClampedArray] }, { v0: [Uint16Array] } ],
  v1: 12.119999885559082,
  v2: 1212,
  v3: 'value 3',
  v4: Uint16Array(8) [
    1, 2, 3, 4,
    5, 6, 7, 8
  ],
  v5: [ 'hello', 'sup' ],
  v6: { hello: 'sup' }
}

FAQs

Package last updated on 29 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts