From bbafe41fcd8721741715e37f2a1d9066cca1c830 Mon Sep 17 00:00:00 2001 From: Norman Reed Date: Sat, 1 May 2021 18:29:42 -0400 Subject: [PATCH] radisk: md5 hash file names > 255 characters --- lib/radisk.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/radisk.js b/lib/radisk.js index 353aae821..b622b5301 100644 --- a/lib/radisk.js +++ b/lib/radisk.js @@ -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;