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

use hash for long filenames #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

paulmars
Copy link

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.

@paulmars
Copy link
Author

Similar to this

thoughtbot/paperclip#1246 (comment)

lib/index.js Outdated
return url + '_' + method + '_' + hash

var namehash = crypto.createHash('sha256');
code = namehash.update("bacon");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be URL. i'll leave it until a conversation happens

@the-jackalope
Copy link

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!

@boxman0617
Copy link
Contributor

#32 I set up this PR to address the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants