Created
October 1, 2022 17:12
-
-
Save kt3k/c56e392ef34c48f19cea6d850152d5cc to your computer and use it in GitHub Desktop.
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
import { | |
iterateReader, | |
readableStreamFromIterable, | |
} from "https://deno.land/[email protected]/streams/mod.ts"; | |
import { createHash } from "https://deno.land/[email protected]/hash/mod.ts"; | |
const path = "data.txt"; | |
function toHex(digest: ArrayBuffer) { | |
return [...new Uint8Array(digest)].map(x => x.toString(16).padStart(2, '0')).join('') | |
} | |
async function main() { | |
Deno.writeTextFileSync(path, "abcdefghi\n".repeat(100000)); | |
let hash = createHash("md5") | |
let iter: any; | |
iter = iterateReader(await Deno.open(path)); | |
for await (const i of iter) { | |
hash.update(i); | |
} | |
console.log("digest 1", toHex(hash.digest())); | |
hash = createHash("md5") | |
iter = readableStreamFromIterable(iterateReader(await Deno.open(path))); | |
for await (const i of iter) { | |
hash.update(i); | |
} | |
console.log("digest 2", toHex(hash.digest())); | |
let bytes: any; | |
bytes = await new Response(readableStreamFromIterable(iterateReader(await Deno.open(path)))).arrayBuffer(); | |
hash = createHash("md5") | |
hash.update(bytes); | |
console.log("digest 3", toHex(hash.digest())); | |
bytes = await new Response((await Deno.open(path)).readable).arrayBuffer(); | |
hash = createHash("md5") | |
hash.update(bytes); | |
console.log("digest 4", toHex(hash.digest())); | |
} | |
await main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment