Skip to content

Commit ccce9a8

Browse files
committed
feat: add option to export Uint8Array for the hash
1 parent fde2239 commit ccce9a8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/dhash.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const toAscii = (hash: string, chars = ["░░", "██"]) => {
7171
return row + chars[0];
7272
};
7373

74-
export const save = async (hash: string, file: string) => {
74+
export const raw = async (hash: string): Promise<Uint8Array> => {
7575
const bin = parseInt(hash, 16).toString(2).split("");
7676
const out = new Image(8, 8);
7777

@@ -91,6 +91,10 @@ export const save = async (hash: string, file: string) => {
9191
}
9292

9393
out.setPixelAt(8, 8, white);
94-
const enc = await out.encode();
94+
return await out.encode();
95+
};
96+
97+
export const save = async (hash: string, file: string): Promise<void> => {
98+
const enc = await raw(hash);
9599
await Deno.writeFile(`${file}.png`, enc);
96100
};

0 commit comments

Comments
 (0)