How to use the binary.characterEncoding 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 / 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);
}