hashBlob
Compute what the SHA-1 object id of a file would be
param | type [= default] | description |
---|---|---|
object | Uint8Array | string | The object to write. If object is a String then it will be converted to a Uint8Array using UTF-8 encoding. |
return | Promise<HashBlobResult> | Resolves successfully with the SHA-1 object id and the wrapped object Uint8Array. |
The object returned has the following schema:
type HashBlobResult = {
oid: string; // The SHA-1 object id
type: 'blob'; // The type of the object
object: Uint8Array; // The wrapped git object (the thing that is hashed)
format: 'wrapped'; // The format of the object
}
Example Code:
let { oid, type, object, format } = await git.hashBlob({
object: 'Hello world!',
})
console.log('oid', oid)
console.log('type', type)
console.log('object', object)
console.log('format', format)
Tip: If you need a clean slate, expand and run this snippet to clean up the file system.
window.fs = new LightningFS('fs', { wipe: true })
window.pfs = window.fs.promises
console.log('done')