Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

radisk: md5 hash file names > 255 characters #1072

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lib/radisk.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,23 @@
opt.jsonify = true;


function ename(t){ return encodeURIComponent(t).replace(/\*/g, '%2A') }
var crypto, enamemap;
try { // try requiring crypto, should only succeed on node
crypto = require("crypto");
enamemap = new Map(); // keep an in-memory map of known hashes
opt.maxKeyLength = opt.maxKeyLength < 0 ? opt.maxKeyLength : opt.maxKeyLength || 255; // feature can be disabled by setting opt.maxKeyLength <= 32
} catch (e) { delete opt.maxKeyLength }
function ename(t) {
var s = encodeURIComponent(t).replace(/\*/g, '%2A');
if (crypto && opt.maxKeyLength > 32 && s.length > opt.maxKeyLength) {
if (!enamemap.has(s)) {
enamemap.set(s, crypto.createHash('md5').update(s).digest('hex'));
// TODO evict old map entries, or add this entry to %1C
}
return enamemap.get(s);
}
return s;
}
function atomic(v){ return u !== v && (!v || 'object' != typeof v) }
var timediate = (typeof setImmediate === "undefined")? setTimeout : setImmediate;
var puff = setTimeout.puff || timediate;
Expand Down