Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@hookun/bitbybit

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hookun/bitbybit - npm Package Compare versions

Comparing version 0.0.8 to 0.0.10

lib/BitReader.d.ts

8

lib/BitWriter.d.ts

@@ -1,6 +0,4 @@

export declare class BitWriter {
readonly view: DataView;
private byteOffset;
private bitOffset;
private byte;
import { Wrapper } from './Wrapper';
export declare class BitWriter extends Wrapper {
private tempByte;
constructor(buffer: ArrayBuffer);

@@ -7,0 +5,0 @@ get buffer(): ArrayBuffer;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const WordSize = 8;
class BitWriter {
const constants_1 = require("./constants");
const Wrapper_1 = require("./Wrapper");
const getValueInBits_1 = require("./getValueInBits");
class BitWriter extends Wrapper_1.Wrapper {
constructor(buffer) {
this.view = new DataView(buffer);
this.byteOffset = 0;
this.bitOffset = 0;
this.byte = 0;
super(buffer);
this.tempByte = 0;
}

@@ -16,21 +16,17 @@ get buffer() {

const { view } = this;
let { byte, bitOffset, byteOffset } = this;
while (0 < bitLength) {
const size = Math.min(WordSize - bitOffset, bitLength);
bitOffset += size;
byte += Math.floor(value / (2 ** (bitLength - size))) * (2 ** (WordSize - bitOffset));
if (bitOffset === WordSize) {
view.setUint8(byteOffset, byte);
byte = bitOffset = 0;
byteOffset++;
let consumed = 0;
while (consumed < bitLength) {
const { bitOffset, byteOffset } = this;
const size = Math.min(constants_1.WordSize - bitOffset, bitLength - consumed);
this.tempByte += getValueInBits_1.getValueInBits(value, bitLength, consumed, consumed + size) * (2 ** (constants_1.WordSize - (bitOffset + size)));
consumed += size;
if (this.step(size)) {
view.setUint8(byteOffset, this.tempByte);
this.tempByte = 0;
}
bitLength -= size;
}
this.byte = byte;
this.bitOffset = bitOffset;
this.byteOffset = byteOffset;
}
end() {
if (0 < this.bitOffset) {
this.view.setUint8(this.byteOffset, this.byte);
if (!this.done && 0 < this.bitOffset) {
this.view.setUint8(this.byteOffset, this.tempByte);
}

@@ -37,0 +33,0 @@ return this.buffer;

@@ -0,5 +1,10 @@

export * from './BitReader';
export * from './BitWriter';
export * from './Wrapper';
export * from './constants';
export * from './createBuffer';
export * from './createBufferFromString';
export * from './getBit';
export * from './getBitInByte';
export * from './getValueInBits';
export * from './listBit';

@@ -6,0 +11,0 @@ export * from './listBitHasState';

@@ -6,6 +6,11 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./BitReader"));
__export(require("./BitWriter"));
__export(require("./Wrapper"));
__export(require("./constants"));
__export(require("./createBuffer"));
__export(require("./createBufferFromString"));
__export(require("./getBit"));
__export(require("./getBitInByte"));
__export(require("./getValueInBits"));
__export(require("./listBit"));

@@ -12,0 +17,0 @@ __export(require("./listBitHasState"));

@@ -11,3 +11,3 @@ {

},
"version": "0.0.8",
"version": "0.0.10",
"license": "Apache-2.0",

@@ -14,0 +14,0 @@ "author": {

# @hookun/bitbybit
[![codecov](https://codecov.io/gh/hookun/bitbybit/branch/master/graph/badge.svg)](https://codecov.io/gh/hookun/bitbybit)
![CI Setup](https://github.com/hookun/bitbybit/workflows/CI%20Setup/badge.svg)
Utilities for ArrayBuffer.

@@ -4,0 +7,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc