Merge pull request #21664 from overleaf/jpa-blob-hash

[overleaf-editor-core] stricter types for Blob interface

GitOrigin-RevId: 8595fce0d5c98074d2313be5a5634e80f92c68b5
This commit is contained in:
Jakob Ackermann
2024-11-08 09:07:05 +00:00
committed by Copybot
parent 122d89a831
commit a3d8caf87b
4 changed files with 18 additions and 34 deletions
@@ -79,23 +79,12 @@ function getBackend(projectId) {
}
async function makeBlobForFile(pathname) {
async function getByteLengthOfFile() {
const stat = await fs.promises.stat(pathname)
return stat.size
}
async function getHashOfFile(blob) {
const stream = fs.createReadStream(pathname)
const hash = await blobHash.fromStream(blob.getByteLength(), stream)
return hash
}
const blob = new Blob()
const byteLength = await getByteLengthOfFile()
blob.setByteLength(byteLength)
const hash = await getHashOfFile(blob)
blob.setHash(hash)
return blob
const { size: byteLength } = await fs.promises.stat(pathname)
const hash = await blobHash.fromStream(
byteLength,
fs.createReadStream(pathname)
)
return new Blob(hash, byteLength)
}
async function getStringLengthOfFile(byteLength, pathname) {