@viegg/ed2k-link

0.0.2 • Public • Published

@viegg/ed2k-link

This is a fork of https://github.com/lightrabbit/ed2k-link

The original code will throw an 0308010C:digital envelope routines::unsupported error in nodejs v17+ while calling crypto.createHash('md4'), see this for detail.

This fork fixed it by using a wasm md4 hash function which stole from webpack

The wasm version is almost as fast as nodejs's original crypto module, took 3 seconds to calculate a 2GB file's ed2k link in my MBP-2018.


A simple module to parse/generate ed2k link for nodejs.

Installation

You can use this command to install:

npm install @viegg/ed2k-link

Usage

You should require the module first:

ed2k = require('@viegg/ed2k-link');

Example

Parse a ed2k url

Code:

ed2k.parse("ed2k://|file|foo.bar|123|0123456789ABCDEF0123456789ABCDEF|/");

Output:

{ filename: 'foo.bar',
  ed2k: '0123456789ABCDEF0123456789ABCDEF',
  aich: '',
  hashset: [],
  sources: { client: [], url: [] },
  length: 123 }

Convert Ed2kLink to ed2k url string

Code:

var link = ed2k.parse("ed2k://|file|foo.bar|123|0123456789ABCDEF0123456789ABCDEF|/");
link.toString();

Output:

ed2k://|file|foo.bar|123|0123456789ABCDEF0123456789ABCDEF|/

Generate Ed2kLink from file:

Code:

//node-like callback
ed2k.generate("./foo.bar", function(err, link) {
  console.log(link);
});
//Promise
ed2k.generate("./foo.bar").then(function(link) {
  console.log(link);
});

Output:

{ filename: 'foo.bar',
  ed2k: '0123456789ABCDEF0123456789ABCDEF',
  aich: '',
  hashset: [],
  sources: { client: [], url: [] },
  length: 123 }

License

The project is released under the MIT license.

Credit

Original author: lightpacerabbit@gmail.com

Readme

Keywords

Package Sidebar

Install

npm i @viegg/ed2k-link

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

31 kB

Total Files

10

Last publish

Collaborators

  • viegg