fetch-vcr
fetch-vcr copied to clipboard
use hash for long filenames
I don't expect you to merge this, there are no tests. But I wanted to propose a solution to a problem.
I was download some URLs that are longer than the filenames my system allows. Which prevents the caching from being saved.
Let me know if I'm not being clear.
Similar to this
https://github.com/thoughtbot/paperclip/issues/1246#issuecomment-18378975
I've also run into this issue using fetch-vcr
!
What might be simpler than modifying the buildHash
method is to alter the buildFilenamePrefix
to simply truncate overly-long filenames like so:
var maxFilenameLength = 255
function buildFilenamePrefix(url, args, hash, suffixLength) {
args = args || { }
url = escape(url).replace(/\//g, '_')
var method = args.method || 'GET'
method = method.toUpperCase()
var filename = url + '_' + method + '_' + hash
var totalLength = filename.length + suffixLength
return totalLength > maxFilenameLength
? filename.slice(0, maxFilenameLength - suffixLength)
: filename
}
Max filename length is capped by every OS I know at 255. Let me know what you think!
https://github.com/philschatz/fetch-vcr/pull/32 I set up this PR to address the issue.