How to use the binary.unpackString function in binary

To help you get started, we’ve selected a few binary examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hellomatty / daap.js / test / binary.js View on Github external
assert.equal(0, binary.unpackInt([0,0,0,0]), 'unpack_int: 0');
assert.equal(1, binary.unpackInt([0,0,0,1]), 'unpack_int: 1');
assert.equal(257, binary.unpackInt([0,0,1,1]), 'unpack_int: 257');

assert.deepEqual([ 0, 0, 0, 0, 0, 0, 0, 1 ], binary.packLong(1), 'pack_long: 1');

assert.equal(1, binary.unpackLong([0,0,0,0,0,0,0,1]), 'unpack_long: 1');

assert.deepEqual([65, 66, 67], binary.packString('ABC'), 'pack_string: abc');;
assert.deepEqual([0xC2, 0xA2], binary.packString('\u00A2'), 'pack_string: U+00A2');;
assert.deepEqual([0xE2, 0x82, 0xAC], binary.packString('\u20AC'), 'pack_string: U+20AC');;

assert.deepEqual('ABC', binary.unpackString([65, 66, 67], 0, 3), 'unpack_string: abc');
assert.deepEqual('\u00a2', binary.unpackString([0xC2, 0xA2], 0, 2), 'unpack_string: \U+00A2');
assert.deepEqual('\u20AC', binary.unpackString([0xE2,0x82,0xAC], 0, 3), 'unpack_string: \U+20AC');
assert.deepEqual('\uFEFFCamino Del Sol', binary.unpackString([0xff, 0xfe, 0x43, 00, 0x61, 00, 0x6d, 00, 0x69, 00, 0x6e, 00, 0x6f, 00, 0x20, 00, 0x44, 00, 0x65, 00, 0x6c, 00, 0x20, 00, 0x53, 00, 0x6f, 00, 0x6c, 00], 0, 30, binary.characterEncoding.utf16));

var now_fixture = 'Sun, 29 Aug 2010 20:20:53 GMT';
var now = new Date(now_fixture);
var now_bytes = [76, 122, 193, 37];
assert.deepEqual(now_bytes, binary.packDate(now), 'pack_date');
assert.deepEqual(now_bytes, binary.packDate(now_fixture), 'pack_date');
assert.equal(now.getTime(), binary.unpackDate(now_bytes, 0).getTime(), 'unpack_date');
github hellomatty / daap.js / test / binary.js View on Github external
assert.deepEqual([0, 0, 1, 1], binary.packInt(257), 'pack_int: 256');

assert.equal(0, binary.unpackInt([0,0,0,0]), 'unpack_int: 0');
assert.equal(1, binary.unpackInt([0,0,0,1]), 'unpack_int: 1');
assert.equal(257, binary.unpackInt([0,0,1,1]), 'unpack_int: 257');

assert.deepEqual([ 0, 0, 0, 0, 0, 0, 0, 1 ], binary.packLong(1), 'pack_long: 1');

assert.equal(1, binary.unpackLong([0,0,0,0,0,0,0,1]), 'unpack_long: 1');

assert.deepEqual([65, 66, 67], binary.packString('ABC'), 'pack_string: abc');;
assert.deepEqual([0xC2, 0xA2], binary.packString('\u00A2'), 'pack_string: U+00A2');;
assert.deepEqual([0xE2, 0x82, 0xAC], binary.packString('\u20AC'), 'pack_string: U+20AC');;

assert.deepEqual('ABC', binary.unpackString([65, 66, 67], 0, 3), 'unpack_string: abc');
assert.deepEqual('\u00a2', binary.unpackString([0xC2, 0xA2], 0, 2), 'unpack_string: \U+00A2');
assert.deepEqual('\u20AC', binary.unpackString([0xE2,0x82,0xAC], 0, 3), 'unpack_string: \U+20AC');
assert.deepEqual('\uFEFFCamino Del Sol', binary.unpackString([0xff, 0xfe, 0x43, 00, 0x61, 00, 0x6d, 00, 0x69, 00, 0x6e, 00, 0x6f, 00, 0x20, 00, 0x44, 00, 0x65, 00, 0x6c, 00, 0x20, 00, 0x53, 00, 0x6f, 00, 0x6c, 00], 0, 30, binary.characterEncoding.utf16));

var now_fixture = 'Sun, 29 Aug 2010 20:20:53 GMT';
var now = new Date(now_fixture);
var now_bytes = [76, 122, 193, 37];
assert.deepEqual(now_bytes, binary.packDate(now), 'pack_date');
assert.deepEqual(now_bytes, binary.packDate(now_fixture), 'pack_date');
assert.equal(now.getTime(), binary.unpackDate(now_bytes, 0).getTime(), 'unpack_date');
github hellomatty / daap.js / lib / song.js View on Github external
var Song = exports.Song = function(options) {
  options = options || {};

  if (!options.file) {
    throw "Song constructor needs a file";
  }

  var song = this;

  var tags = {};

  var fd = fs.openSync(options.file, 'r');
  var reader = new BinaryFile(fd);

  if (binary.unpackString(reader.getBytesAt(0, 3), 0, 3) == "ID3") {
    sys.log("[id3v2] scanning tags...");
    tags = ID3v2.readTagsFromData(reader);
  }

  fs.stat(options.file, function(err, stats) {
    if (err) {
      throw "Failed to stat " + song.file;
    }
    
    song.size = stats.size;
  });

  this.file = options.file;

  this.artist = options.artist || tags.artist || options.file;
  this.name = options.name || tags.title || options.file;
github hellomatty / daap.js / lib / song.js View on Github external
BinaryFile.prototype.getStringWithCharsetAt = function(offset, length, charset) {
  var encoding;
  switch( charset.toLowerCase() ) {
    case 'utf-8':
      encoding = binary.characterEncoding.utf8;
      break;
    case 'utf-16':
      encoding = binary.characterEncoding.utf16;
      break;
    default:
      throw "Encoding '" + charset + "' not supported";
  }

  return binary.unpackString(this.getBytesAt(offset, length), 0, length, encoding);
}
github hellomatty / daap.js / lib / song.js View on Github external
BinaryFile.prototype.getStringAt = function(offset, length) {
  return binary.unpackString(this.getBytesAt(offset, length), 0, length);
}
github hellomatty / daap.js / lib / dmap.js View on Github external
var decode = exports.decode = function (buffer, index) {
  index = index || 0;

  var decodedTag = binary.unpackString(buffer, index, 4);
  
  return [
    decodedTag,
    unpacker(decodedTag)(buffer, index + 8, binary.unpackInt(buffer, index+4))
  ];
};