Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Homepage - API Documentation - npm
var Encoder = require('bitsparrow').Encoder;
var buffer = new Encoder()
.uint8(100)
.string("Foo")
.end();
console.log(buffer); // Uint8Array | Buffer [0x64,0x03,0x46,0x6f,0x6f]
The type of the buffer used by BitSparrow changes depending on
the environment - when used within Node.js it becomes a Buffer
,
otherwise the more generic Uint8Array
is used.
When piping data through a WebSocket in the Browser, set the
binary
mode to use ArrayBuffer
over Blob
, and create the
Uint8Array
view on top of it:
var bitsparrow = require('bitsparrow');
var socket = new WebSocket('ws://example.com/');
socket.binaryType = 'arraybuffer';
socket.onmessage = function(event) {
let decoder = new bitsparrow.Decoder(new Uint8Array(event.data));
// Read the data ...
}
socket.onpen = function() {
let decoder = new bitsparrow.Encoder().string('Hello World');
// Send internal `ArrayBuffer` from `Uint8Array`
socket.send(decoder.end().buffer);
}
Each method on the Encoder
will consume the instance of the
struct. If you need to break the monad chain, store the
intermediate state of the encoder, e.g.:
var Decoder = require('bitsparrow').Decoder;
var buffer = new Uint8Array([0x64,0x03,0x46,0x6f,0x6f]);
var decoder = new Decoder(buffer);
console.log(decoder.uint8()); // -> 100
console.log(decoder.string()); // -> "Foo"
console.log(decoder.end()); // -> true
Decoder takes a reference to the buffer and allows you to
retrieve the values in order they were encoded. Calling the
end
method is optional, it will return true if you have
read the entire buffer, which can be handy if you are reading
multiple messages stacked on a single buffer.
The goal of this library is to reduce both the size and parsing time of data when compared to JSON or msgpack. While JavaScript lacks low level primitive number type transmutations, using pre-cached TypedArrays yields very fast results. You can run benchmarks with:
npm run bench
Most notably, fixed size number decoding, such as float64
and uint32
, is
much faster than even the native JSON implementation in V8, with time per
operation being less than 100 nanoseconds on most (even old) CPUs.
Copyright (c) 2016 BitSparrow
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
JavaScript implementation of BitSparrow - http://bitsparrow.io/
We found that bitsparrow demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.