Created
December 16, 2024 22:15
-
-
Save hubgit/c9e0abd4c54ab6e936aef6bd130db478 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 * as bencode from 'https://deno.land/x/[email protected]/mod.ts' | |
import { gtin } from 'npm:cdigit' | |
import ISBN from 'npm:isbn3' | |
// zstd -d data/aa_isbn13_codes_20241204T185335Z.benc.zst | |
const data = await Deno.readFile('data/aa_isbn13_codes_20241204T185335Z.benc').then(bencode.decode) | |
for (const [key, value] of Object.entries(data as Record<string, Uint8Array>)) { | |
console.log(key) | |
let streak = true | |
let position = 0 | |
const view = new DataView(value.buffer) | |
for (let byteOffset = 0; byteOffset < view.byteLength; byteOffset += 4) { | |
const value = view.getUint32(byteOffset, true) | |
if (streak) { | |
for (let i = 0; i < value; i++) { | |
const isbn = String(978000000000 + position) | |
const checked = gtin.generate(isbn) | |
const data = ISBN.parse(checked) | |
console.log(data) | |
position++ | |
} | |
} else { | |
position += value | |
} | |
streak = !streak | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment