StructuredDataView
Provides a low-level interface for reading and writing structured data in a binary ArrayBuffer.
Installation
From NPM:
;
From CDN:
<script src="http://unpkg.com/structured-data-view/dist/structured-data-view.js"></script>
Examples
You can create a buffer and fill it with structed data.
const struct = a: 1 b: 5 c: 2; const buffer = 100; const view = struct buffer; view; const data0 = view; console; // 12console; // 3
Use StructuredDataView to manipulate binary data such as blob or image data.
{ const img = ; imgcrossOrigin = 'anonymous'; return { img { ; }; imgsrc = url; };} { const src = 'https://p1.ssl.qhimg.com/t011f60e5399df3d7a6.png'; const img = await ; const canvas = document; const context = canvas; context; const imageData = context; const buffer = imageDatadatabuffer; const struct = r: 8 g: 8 b: 8 a: 8 ; const view = struct buffer; // make image color black an white view; context;};
Api
constructor(structure, arrayBufferOrLength)
The constructor of the StructuredDataView.
- The structure is a metadata of the StructuredDataView.
const structure = a: 1 // property a is 1 bitwidth. b: 3 // property b is 3 bitwidth. c: 4 // property c is 4 bitwidth, d: Number // property d is a number type e: Boolean // property e is a boolean type // create an array buffer with 1000 structured data items.const view = structure 1000;
setData(index, data)
Set data to StructuredDataView.
view
getData(index)
Get data from StructuredDataView.
forEach(callback)
The forEach() method executes a provided function once for each structured data blocks.
const view = structure 1000; view;
fill(data)
Fill each structed data blocks with specified data.
const buffer = imageDatadatabuffer; const struct = r: 8 g: 8 b: 8 a: 8; const view = struct buffer;view; // red channel set to zero.
License
MIT