diff --git a/plugins/signed-integrity/cli.js b/plugins/signed-integrity/cli.js index d0063a3..8b4991e 100644 --- a/plugins/signed-integrity/cli.js +++ b/plugins/signed-integrity/cli.js @@ -117,32 +117,28 @@ let getFileIntegrity = async (path, algos) => { // are we working with a file? if (fileInfo.isFile) { - - // initialize - content = new Uint8Array() - var buf = new Uint8Array(1000); - - // read the first batch - var numread = file.readSync(buf); - - // 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) + const reader = file.readable.getReader(); + const chunks = []; + + while (true) { + const { done, value } = await reader.read(); + if (done) { + break; } - content = new_content - - // read some more - numread = file.readSync(buf); + chunks.push(value); + } + + 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; } }