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 callingcrypto.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.
You can use this command to install:
npm install @viegg/ed2k-link
You should require the module first:
ed2k = require('@viegg/ed2k-link');
Code:
ed2k.parse("ed2k://|file|foo.bar|123|0123456789ABCDEF0123456789ABCDEF|/");
Output:
{ filename: 'foo.bar',
ed2k: '0123456789ABCDEF0123456789ABCDEF',
aich: '',
hashset: [],
sources: { client: [], url: [] },
length: 123 }
Code:
var link = ed2k.parse("ed2k://|file|foo.bar|123|0123456789ABCDEF0123456789ABCDEF|/");
link.toString();
Output:
ed2k://|file|foo.bar|123|0123456789ABCDEF0123456789ABCDEF|/
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 }
The project is released under the MIT license.
Original author: lightpacerabbit@gmail.com