Git Product home page Git Product logo

bit-buffer's People

Contributors

amitbeck avatar icewind1991 avatar inolen avatar luxaritas avatar malvineous avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

bit-buffer's Issues

new BitView() fails with byteOffset specified

If the BitView constructor is invoked with (non-zero) byteOffset and no byteLength, it fails with Uncaught RangeError: Invalid typed array length error.

To replicate:

$ node
> BitView = require('bit-buffer').BitView;
> array = new ArrayBuffer(8);
> bv = new BitView(array, 4);
Uncaught RangeError: Invalid typed array length: 8
    at new Uint8Array (<anonymous>)
    at new BitView (.../node_modules/bit-buffer/bit-buffer.js:22:15)

I think the solution would be to change line 20 to

byteLength = byteLength || source.byteLength-byteOffset /* ArrayBuffer */ || source.length-byteOffset /* Buffer */;

Idea: fseek

It would be useful to have a fseek function with seek_cur and seek_set modes. Is bb.byteIndex = newOffset; // seek_set and bb.byteIndex += offset; // seek_cur equivalent here?

Cannot find 'Buffer' in typescript definition while compiling with ionic

[23:52:56] typescript: node_modules/bit-buffer/bit-buffer.d.ts, line: 5
Cannot find name 'Buffer'.

   L4:  	export class BitStream {
   L5:  		constructor(source: ArrayBuffer | Buffer, byteOffset?: number, byteLength?: number)

[23:52:56] typescript: node_modules/bit-buffer/bit-buffer.d.ts, line: 10
Cannot find name 'Buffer'.

   L9:  bitsLeft: number;
  L10:  buffer: Buffer;

[23:52:56] typescript: node_modules/bit-buffer/bit-buffer.d.ts, line: 15
L11: index: number;

[23:52:56] typescript: node_modules/bit-buffer/bit-buffer.d.ts, line: 35
'writeBits', which lacks return-type annotation, implicitly has an 'any' return type.

  L15:  		writeBits(value: number, bits: number);

        'writeBoolean', which lacks return-type annotation, implicitly has an 'any' return type. 

  L35:  		writeBoolean(value: number);

[23:52:56] typescript: node_modules/bit-buffer/bit-buffer.d.ts, line: 37
'writeInt8', which lacks return-type annotation, implicitly has an 'any' return type.

[23:52:56] typescript: node_modules/bit-buffer/bit-buffer.d.ts, line: 39
L37: writeInt8(value: number);

[23:52:56] typescript: node_modules/bit-buffer/bit-buffer.d.ts, line: 41
'writeUint8', which lacks return-type annotation, implicitly has an 'any' return type.

  L39:  		writeUint8(value: number);

        'writeInt16', which lacks return-type annotation, implicitly has an 'any' return type. 

  L41:  		writeInt16(value: number);

[23:52:56] typescript: node_modules/bit-buffer/bit-buffer.d.ts, line: 43

        'writeUint16', which lacks return-type annotation, implicitly has an 'any' return type. 

  L43:  		writeUint16(value: number);

[23:52:56] typescript: node_modules/bit-buffer/bit-buffer.d.ts, line: 45
'writeInt32', which lacks return-type annotation, implicitly has an 'any' return type.

  L45:  		writeInt32(value: number);

[23:52:56] typescript: node_modules/bit-buffer/bit-buffer.d.ts, line: 47
'writeUint32', which lacks return-type annotation, implicitly has an 'any' return type.

  L47:  		writeUint32(value: number);

[23:52:56] typescript: node_modules/bit-buffer/bit-buffer.d.ts, line: 49
'writeFloat32', which lacks return-type annotation, implicitly has an 'any' return type.
[23:52:56] typescript: node_modules/bit-buffer/bit-buffer.d.ts, line: 51

  L49:  		writeFloat32(value: number);

        'writeFloat64', which lacks return-type annotation, implicitly has an 'any' return type. 

[23:52:56] typescript: node_modules/bit-buffer/bit-buffer.d.ts, line: 57
L51: writeFloat64(value: number);

        'writeASCIIString', which lacks return-type annotation, implicitly has an 'any' return type. 

  L57:  		writeASCIIString(data: string, length?: number);

[23:52:56] typescript: node_modules/bit-buffer/bit-buffer.d.ts, line: 59
'writeUTF8String', which lacks return-type annotation, implicitly has an 'any' return type.

  L59:  		writeUTF8String(data: string, length?: number);

[23:52:56] transpile failed
[23:52:56] ionic-app-script task: "build"
[23:52:56] Error: Error

Add LICENSE file

This project is under the MIT license yet no LICENSE file is present. Providing one will be useful in including the notice in things that use this,

_

_

Deprecated usage of new Buffer() and an error in referncing BitStream's buffer property

  1. In BitView's buffer property getter: calling new Buffer() is deprecated, consider using Buffer.from() instead.
  2. In BitStream's buffer property getter: calling new Buffer() (which is, once again, deprecated) with anything other than an array-like object returns an error.
    Therefore you cannot call BitStream's buffer property getter.
    To fix this, you can call Buffer.from(this._view.buffer) or just return this._view.buffer as calling BitView's buffer property getter creates a new Buffer instance every time.

Release new version

The changes introduced in the pull requests that have been merged since 0.0.3 seem to have improved performance by over 15% in my code.

I'm wondering whether a new version of the library could be released so I can make use of these changes.

Thanks

reading in a character bit by bit does not work

I might be misunderstanding how this library works, but I'm not seeing the results I would expect when reading in 8 single bits.

bitBuffer = require('bit-buffer');

// read in an "H" bit by bit
b = Buffer.from('H');
bv = new bitBuffer.BitView(b);
bv.bigEndian = false;
arr = [];
for (let i = 0; i < 8; i++) {
  arr.push(bv.getBits(i, 1));
}

// store some results
arrReversed = [...arr].reverse();
realResult = 'H'.charCodeAt(0).toString(2).padStart(8, '0');
bitViewResult = arrReversed.join('');

// convert back to chars
realResultAsChar = String.fromCharCode(parseInt(realResult, 2));
bitViewResultAsChar = String.fromCharCode(parseInt(bitViewResult, 2));

// print result
console.log({
  realResult,
  bitViewResult,
  realResultAsChar,
  bitViewResultAsChar,
  arr,
  arrReversed,
});

The above code outputs:

{
  realResult: '01001000',
  bitViewResult: '00101111',
  realResultAsChar: 'H',
  bitViewResultAsChar: '/',
  arr: [
    1, 1, 1, 1,
    0, 1, 0, 0
  ],
  arrReversed: [
    0, 0, 1, 0,
    1, 1, 1, 1
  ]
}

I would expect the bitViewResult to match the realResult and I would expect bitViewResultAsChar to be 'H'.

I don't understand why the first 4 bits it reads in are 1.

Thanks anyways for sharing your work!

Release a new version

Hello,

Thanks for your work on this! :-)

Any chance you could make a new release that includes the fix for #22 (LICENSE file) and adding the bigEndian property to the TypeScript declarations (f2cb04d)?

Suggestion: skipBits

It'd be useful in some use cases to have a skipBits function, which just advances the offset without reading any bits - if you know you don't care about the value of some bits, you shouldn't have to read them and compute their value.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.