Read file stream using JavaScript in web browser

落花浮王杯 提交于 2019-12-04 19:25:32

问题


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?


回答1:


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:

  • http://www.html5rocks.com/en/tutorials/file/dndfiles/
  • https://google.github.io/closure-library/api/goog.crypt.Sha1.html


来源:https://stackoverflow.com/questions/18586839/read-file-stream-using-javascript-in-web-browser

工具导航Map