-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
146 additions
and
700 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
declare module 'ipfs-only-hash'; | ||
declare module 'json-bigint'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Based on https://github.com/alanshaw/ipfs-only-hash/blob/master/index.js | ||
// added types and updated dependencies | ||
import {importer, ImporterOptions} from 'ipfs-unixfs-importer'; | ||
|
||
const block = { | ||
get: async (cid: string) => { | ||
throw new Error(`unexpected block API get for ${cid}`); | ||
}, | ||
put: async () => { | ||
throw new Error('unexpected block API put'); | ||
}, | ||
}; | ||
|
||
export const Hash = { | ||
of: async (content: string | Uint8Array, options: ImporterOptions = {}) => { | ||
options = options || {}; | ||
|
||
if (typeof content === 'string') { | ||
content = new TextEncoder().encode(content); | ||
} | ||
|
||
let lastCid; | ||
for await (const {cid} of importer([{content}], block, options)) { | ||
lastCid = cid; | ||
} | ||
|
||
return `${lastCid}`; | ||
}, | ||
}; |
Oops, something went wrong.