Read file stream using javascript in web browser

2019-03-25 05:12发布

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条回答
Luminary・发光体
2楼-- · 2019-03-25 05:27

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:

查看更多
登录 后发表回答