22

In web browser, I want to compute sha1 checksum of a huge file in the local filesystem without sending it to a server.

File API supports to read files from local disk but I guess it reads the entire of the file and put all of them into the memory. It may occur a problem if the file is larger than system memory.

Streams API seems to be useful to solve this problem but I couldn't find how to read a file using the API.

Is there any way to read file stream from local disk using javascript in web browser?

3
  • hmm. XMLHttpRequest seems to be able to open a blob url from URL.createObjectURL. Commented Sep 3, 2013 at 8:44
  • Did you ever find a solution to this problem? I'd like to know the same. Commented Dec 12, 2013 at 16:06
  • @monkeymatrix Not yet. I think the APIs should be improved to solve this problem. Commented Dec 14, 2013 at 13:07

1 Answer 1

13

The file api provides a slice method, so you should be able to read chunks of data

var blob = file.slice(startingByte, endindByte);

The Sha1 class in google's crypto api provides a update method, you should be able to feed the update method with your chunks

source:

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks a lot! It works very well and I write an example here: gist.github.com/npcode/11282867
@npcode Thanks for the link - but the link is now dead?
@BKSpurgeon Yeah, you're right. Here is the new link: gist.github.com/eungjun-yi/11282867
Great that it works, but you chunk the file manually with a loop. Isn't the whole point of Streams that you don't have to do this annoying chunking yourself?
@Phil You're right, it would be better to you FileReader.onload, it already reads chunks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.