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 3.0.2 to 4.0.0

9

index.js

@@ -5,3 +5,4 @@ 'use strict'

exports.encode = function (buf, opts) {
function encode (buf) {
if (typeof buf === 'string') return encode(decode(buf))
if (buf.length !== 32) throw new Error('Invalid buffer')

@@ -11,3 +12,4 @@ return Buffer.from(buf).toString('hex')

exports.decode = function (str) {
function decode (str) {
if (Buffer.isBuffer(str)) return decode(encode(str))
var match = /(?:[a-z]+:\/\/(?:dat\.land\/)?)?([^/]{64})/.exec(str)

@@ -17,1 +19,4 @@ if (!match) throw new Error('Invalid key')

}
exports.encode = exports.toBuf = encode
exports.decode = exports.toStr = decode
{
"name": "dat-encoding",
"version": "3.0.2",
"version": "4.0.0",
"license": "MIT",

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

@@ -21,12 +21,18 @@

### .encode(buf[, opts])
### .encode(buf)
### .toStr(buf)
Encode `buf` into a hex string. Throws if `buf` isn't 32 bytes of length.
If `buf` is already a string, checks if it's valid and returns it.
### .decode(str)
### .toBuf(str)
Decode `str` into its binary representation. Also supports `dat://` and `dat.com/` links. Throws if the raw link isn't 64 bytes of base64.
If `str` is already a buffer, checks if it's valid and returns it.
## License
MIT

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

t.equal(enc.encode(Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')), '6161616161616161616161616161616161616161616161616161616161616161')
t.equal(enc.encode('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'), '6161616161616161616161616161616161616161616161616161616161616161')
t.throws(function () { enc.encode('tooshort') })
t.equal(enc.encode(Buffer('0100000000000000ffffffff0000000000008004010000004012800201000000', 'hex')), '0100000000000000ffffffff0000000000008004010000004012800201000000')
t.equal(enc.encode, enc.toBuf)
t.end()

@@ -45,2 +45,4 @@ })

t.equal(enc.decode, enc.toStr)
t.end()

@@ -47,0 +49,0 @@ })

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