mo-arraybuffer-tools
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

[ ] write proper tests [ ] create package.json browser/react-native fields

one package but distinct include (import x from 'package/feature') with code removal? browser, electron, react-native keys?

package keywords

"test": "xo && ava && tsd-check"

travis? https://github.com/sindresorhus/delay/blob/master/test.js

arraybuffer-hex -> node way, TextEncoder way, fallback

arraybuffer-base64 -> same

arraybuffer-binarystring

arraybuffer-utf8

arraybuffer-nodebuffer

arraybuffer-sha256|sha512|sha1|md5 arraybuffer-hmac

var uint8array = new TextEncoder().encode(string); var string = new TextDecoder(encoding).decode(uint8array);

export function encode(source: ArrayBufferLike): string { let buffer = new Uint8Array(source); let result: string[] = []; for (let i=0; i<buffer.length; i++) { result.push(String.fromCharCode(buffer[i])); } return result.join(''); }

export function decode(source: string): ArrayBufferLike { let result = new Uint8Array(source.length); for (let i=0; i<source.length; i++) result[i] = source.charCodeAt(i); return result.buffer; }

function str2ab(str) { var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char var bufView = new Uint16Array(buf); for (var i=0, strLen=str.length; i<strLen; i++) { bufView[i] = str.charCodeAt(i); } return buf; }

return String.fromCharCode.apply(null, new Uint16Array(buf));

function arrayBufferToString(buffer){

var bufView = new Uint16Array(buffer);
var length = bufView.length;
var result = '';
var addition = Math.pow(2,16)-1;

for(var i = 0;i<length;i+=addition){

    if(i + addition > length){
        addition = length - i;
    }
    result += String.fromCharCode.apply(null, bufView.subarray(i,i+addition));
}

return result;

}

Readme

Keywords

none

Package Sidebar

Install

npm i mo-arraybuffer-tools

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

228 kB

Total Files

69

Last publish

Collaborators

  • mm22