GitXplorerGitXplorer
n

node-butils

public
7 stars
2 forks
3 issues

Commits

List of commits on branch master.
Unverified
ae49f7a87e08d9213c166277a5bee568aa69222a

dont allocate new buffers

nnlf committed 11 years ago
Unverified
e8c66078efd86b97dd7480f5945899ceb81347e5

cleanup and a ton of tests

nnlf committed 11 years ago
Unverified
d23cd1b5cc702d6f20d2a3958d2fb7c497a3da77

version bump

nnlf committed 11 years ago
Unverified
298541d0984b76ea9b9aaeedfc5534f9c1993931

Merge pull request #3 from DanielBarnes/master

nnlf committed 11 years ago
Unverified
506f1ec0c66e97b127e731c536a6570a9fa823a2

different bit aks craziness

ddacbd committed 11 years ago
Unverified
70b95e9e96d36b6809d38a721c0f26e084fb21f7

readme

ddacbd committed 11 years ago

README

The README file for this repository.

butils

###Bufferwise binary operations

  • getBit(buffer, offset) returns true or false
  • setBit(buffer, offset, boolean) returns the changed byte
  • XOR(buffer, buffer2) returns the modifed first buffer
  • OR(buffer, buffer2) returns the modifed first buffer
  • AND(buffer, buffer2) return the modifed first buffer
  • NOT(buffer) return the modifed buffer
  • EQUAL(buffer, buffer2) returns a boolean
  • leftShift(buffer, offset) returns a NEW buffer
  • rightShift(buffer, offset) returns a NEW buffer
  • signedRightShift(buffer, offset) returns a NEW buffer

These are some helper functions that appear to be significantly faster than core Buffer manipulation functions.

Functions included

  • readInt(buffer, offset) -- (buffer.readInt8(offset))
  • writeInt(buffer, int, offset) -- (buffer.writeInt8(int, offset))
  • readInt32(buffer, offset) -- (buffer.readUInt32BE(offset))
  • writeInt32(buffer, int, offset) -- (buffer.writeUInt32BE(int, offset))
  • readString(buffer, start, end) -- (buffer.toString(start, end))
  • writeString(buffer, str, offset) -- (Buffer.write(str, 'utf8', offset))
  • readVarint(buffer, offset) -- (no equivalent)
  • writeVarint(buffer, int, offset) -- (no equivalent)

Note that the Int32 functions are currently unsigned and big endian only, though I'd happily accept pull requests to add more functionality.

Benchmark

100,000,000 iterations of each function. (see bench.js)

  • Buffer#writeInt8: 1225ms
  • butils#writeInt: 166ms
  • Buffer#readInt8: 761ms
  • butils#readInt: 164ms
  • Buffer#writeUInt32BE: 1544ms
  • butils#writeInt32: 257ms
  • Buffer#readUInt32BE: 1525ms
  • butils#readInt32: 323ms
  • Buffer#write: 45101ms
  • butils#writeString: 2509ms
  • Buffer#toString: 17505ms
  • butils#readString: 7340ms
  • butils#writeVarint: 1264ms
  • butils#readVarint: 4777ms