dat-encoding
Advanced tools
Comparing version 2.0.2 to 2.1.0
@@ -9,5 +9,6 @@ 'use strict' | ||
exports.encode = function (buf) { | ||
exports.encode = function (buf, opts) { | ||
if (buf.length !== 32) throw new Error('Invalid buffer') | ||
buf = Buffer.from(buf) | ||
if (opts && opts.legacy) return buf.toString('hex') | ||
var str = encoding.encode(buf) | ||
@@ -14,0 +15,0 @@ while (str.length < 50) str = '0' + str |
{ | ||
"name": "dat-encoding", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": "juliangruber/dat-encoding", |
@@ -21,6 +21,8 @@ | ||
### .encode(buf) | ||
### .encode(buf[, opts]) | ||
Encode `buf` into a string that works well in urls. Throws if `buf` isn't 32 bytes of length. | ||
Encode `buf` into a string that works well in urls. Throws if `buf` isn't 32 bytes of length. | ||
Pass `legacy: true` to create an old style hex encoded link. | ||
### .decode(str) | ||
@@ -27,0 +29,0 @@ |
15
test.js
@@ -10,2 +10,17 @@ var test = require('tape') | ||
t.equal(enc.encode(Buffer('0100000000000000ffffffff0000000000008004010000004012800201000000', 'hex')), '00waum9lsz88rt2zltcysggj4yc0odk8uwwrq05shegvktfgu8') | ||
t.test('legacy: true', function (t) { | ||
t.equal( | ||
enc.encode(Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')).length, | ||
50 | ||
) | ||
t.equal( | ||
enc.encode( | ||
Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'), | ||
{ legacy: true } | ||
).length, | ||
64 | ||
) | ||
t.end() | ||
}) | ||
t.end() | ||
@@ -12,0 +27,0 @@ }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4925
92
34