kopia lustrzana https://gitlab.com/rysiekpl/libresilient
Merge branch 'signed-integrity-cli-better-file-reading' into 'master'
signed-integrity cli: Improve file reading See merge request rysiekpl/libresilient!24merge-requests/23/merge
commit
8f23bc6965
|
@ -117,32 +117,28 @@ let getFileIntegrity = async (path, algos) => {
|
||||||
|
|
||||||
// are we working with a file?
|
// are we working with a file?
|
||||||
if (fileInfo.isFile) {
|
if (fileInfo.isFile) {
|
||||||
|
const reader = file.readable.getReader();
|
||||||
// initialize
|
const chunks = [];
|
||||||
content = new Uint8Array()
|
|
||||||
var buf = new Uint8Array(1000);
|
while (true) {
|
||||||
|
const { done, value } = await reader.read();
|
||||||
// read the first batch
|
if (done) {
|
||||||
var numread = file.readSync(buf);
|
break;
|
||||||
|
|
||||||
// read the rest, if there is anything to read
|
|
||||||
while (numread !== null) {
|
|
||||||
//console.log(` +-- read: ${numread}`)
|
|
||||||
//console.log(` +-- length: ${content.length}`)
|
|
||||||
|
|
||||||
// there has to be a better way...
|
|
||||||
var new_content = new Uint8Array(content.length + numread);
|
|
||||||
//console.log(` +-- new length: ${new_content.length}`)
|
|
||||||
new_content.set(content)
|
|
||||||
if (buf.length === numread) {
|
|
||||||
new_content.set(buf, content.length)
|
|
||||||
} else {
|
|
||||||
new_content.set(buf.slice(0, numread), content.length)
|
|
||||||
}
|
}
|
||||||
content = new_content
|
chunks.push(value);
|
||||||
|
}
|
||||||
// read some more
|
|
||||||
numread = file.readSync(buf);
|
let length = 0;
|
||||||
|
for (const chunk of chunks) {
|
||||||
|
length += chunk.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
content = new Uint8Array(length);
|
||||||
|
|
||||||
|
let index = 0;
|
||||||
|
for (const chunk of chunks) {
|
||||||
|
content.set(chunk, index);
|
||||||
|
index += chunk.length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue