Skip to content

Instantly share code, notes, and snippets.

@hubgit
Created December 16, 2024 22:15
Show Gist options
  • Save hubgit/c9e0abd4c54ab6e936aef6bd130db478 to your computer and use it in GitHub Desktop.
Save hubgit/c9e0abd4c54ab6e936aef6bd130db478 to your computer and use it in GitHub Desktop.
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