问题描述
在网络浏览器中,我想在本地文件系统中计算一个巨大文件的sha1校验和,而不将其发送到服务器。
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.
似乎对解决这个问题很有用,但我找不到如何使用API读取文件。
Streams API seems to be useful to solve this problem but I couldn't find how to read a file using the API.
有没有办法在Web浏览器中使用javascript从本地磁盘读取文件流?
Is there any way to read file stream from local disk using javascript in web browser?
推荐答案
文件api提供了一种切片方法,所以你应该能够读取数据块
The file api provides a slice method, so you should be able to read chunks of data
var blob = file.slice(startingByte, endindByte);
google的crypto api中的Sha1类提供了一种更新方法,你应该可以提供更新方法你的块
The Sha1 class in google's crypto api provides a update method, you should be able to feed the update method with your chunks
来源:
- http://www.html5rocks.com/en/tutorials/file/dndfiles/
- https://google.github.io/closure-library/api/goog.crypt.Sha1.html
这篇关于在Web浏览器中使用javascript读取文件流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!