Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dat-encoding

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dat-encoding - npm Package Compare versions

Comparing version 1.2.0 to 2.0.0

8

example.js
var encoding = require('.')
var input = 'quite rad'
var encoded = encoding.encode(input)
console.log('%s -> %s', input, encoded)
console.log('%s -> %s', encoded, encoding.decode(encoded))
var link = '2fdiu7i6kpzx4h9qos6eqldjghd2ut5hx0e8bekm0bkwiax3dt'
var buf = encoding.decode(link)
console.log('%s -> %s', link, buf)
console.log('%s -> %s', buf, encoding.encode(buf))

@@ -10,2 +10,3 @@ 'use strict'

exports.encode = function (buf) {
if (buf.length !== 32) throw new Error('Invalid buffer')
buf = Buffer.from(buf)

@@ -17,4 +18,5 @@ return encoding.encode(buf)

str = str.slice(str.lastIndexOf('/') + 1)
if (str.length === 64) return Buffer.from(str, 'hex')
if (/[0-9a-f]{64}/i.test(str)) return Buffer.from(str, 'hex')
if (str.length !== 50) throw new Error('Invalid key')
return Buffer.from(encoding.decode(str))
}
{
"name": "dat-encoding",
"version": "1.2.0",
"version": "2.0.0",
"license": "MIT",

@@ -5,0 +5,0 @@ "repository": "juliangruber/dat-encoding",

@@ -13,6 +13,6 @@

var input = 'quite rad'
var encoded = encoding.encode(input)
console.log('%s -> %s', input, encoded)
console.log('%s -> %s', encoded, encoding.decode(encoded))
var link = '2fdiu7i6kpzx4h9qos6eqldjghd2ut5hx0e8bekm0bkwiax3dt'
var buf = encoding.decode(link)
console.log('%s -> %s', link, buf)
console.log('%s -> %s', buf, encoding.encode(buf))
```

@@ -19,0 +19,0 @@

@@ -5,5 +5,6 @@ var test = require('tape')

test('encode', function (t) {
t.equal(typeof enc.encode(Buffer('hey')), 'string')
t.equal(enc.encode(Buffer('hey')), '42n3t')
t.equal(enc.encode('hey'), '42n3t')
t.equal(typeof enc.encode(Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')), 'string')
t.equal(enc.encode(Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')), '2fdiu7i6kpzx4h9qos6eqldjghd2ut5hx0e8bekm0bkwiax3dt')
t.equal(enc.encode('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'), '2fdiu7i6kpzx4h9qos6eqldjghd2ut5hx0e8bekm0bkwiax3dt')
t.throws(function () { enc.encode('tooshort') })
t.end()

@@ -13,7 +14,19 @@ })

test('decode', function (t) {
t.ok(Buffer.isBuffer(enc.decode('42n3t')))
t.deepEqual(enc.decode('42n3t'), Buffer('hey'))
t.deepEqual(enc.decode('http://dat.lin/42n3t'), Buffer('hey'))
t.deepEqual(enc.decode('https://dat.lin/42n3t'), Buffer('hey'))
t.deepEqual(enc.decode('dat://42n3t'), Buffer('hey'))
t.ok(Buffer.isBuffer(enc.decode('42n3t42n3t42n3t42n3t42n3t42n3t42n3t42n3t42n3t42n3t')))
t.deepEqual(
enc.decode('2fdiu7i6kpzx4h9qos6eqldjghd2ut5hx0e8bekm0bkwiax3dt'),
Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
)
t.deepEqual(
enc.decode('http://dat.land/2fdiu7i6kpzx4h9qos6eqldjghd2ut5hx0e8bekm0bkwiax3dt'),
Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
)
t.deepEqual(
enc.decode('https://dat.land/2fdiu7i6kpzx4h9qos6eqldjghd2ut5hx0e8bekm0bkwiax3dt'),
Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
)
t.deepEqual(
enc.decode('dat://2fdiu7i6kpzx4h9qos6eqldjghd2ut5hx0e8bekm0bkwiax3dt'),
Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
)

@@ -26,2 +39,4 @@ var legacy = {

t.throws(function () { enc.decode('too short') })
t.end()

@@ -31,4 +46,5 @@ })

test('integration', function (t) {
t.equal(enc.decode(enc.encode(Buffer('hey'))).toString(), 'hey')
var input = Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
t.deepEqual(enc.decode(enc.encode(input)), input)
t.end()
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc