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

Support calculating md5 / sha1 hash for each uploaded files #7

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

Conversation

dzcpy
Copy link
Contributor

@dzcpy dzcpy commented Sep 15, 2014

It is very handful if we could have file's md5 or sha1 after upload, for example, when using it to check duplicated files, as a global unique file name or as database primary key etc.. I tried to do it by using req.file().pipe but I found it's extremely hard without reading through the file again (without hacking the adapter). So I modified skipper-disk package and added this feature. When giving an option

{
  hash: 'md5'
}

In the returned results, it will show file's hash. Example:

[ { fd: '/srv/http/.tmp/uploads/d3cdcbd2-5b6a-4131-b9ce-2a5da00d4f9d.ini',
    size: 115,
    type: 'application/octet-stream',
    filename: 'desktop.ini',
    status: 'bufferingOrWriting',
    field: 'files[]',
    extra: { md5: '359bb6716c7fb00e02d4b681a0bce711' } } ]

if hash option is not given, it will load nothing so there's no perfomance impact when we not using it.
Since it's utilize the same pipe chain as skipper-disk's fs.createWriteStream, the overhead of hash calculation is minimal as well.

@dzcpy dzcpy changed the title Support calculation md5 / sha1 hash of each uploaded files Support calculating md5 / sha1 hash for each uploaded files Sep 15, 2014
@dzcpy
Copy link
Contributor Author

dzcpy commented Jan 23, 2015

@caasjj I think you are right, I modified the code again, thanks for the suggestion

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

Successfully merging this pull request may close these issues.

1 participant