-
Notifications
You must be signed in to change notification settings - Fork 3
/
encode
35 lines (32 loc) · 876 Bytes
/
encode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env node
const fs = require('fs')
const { promisify } = require('util')
const read = promisify(fs.readFile)
const write = promisify(fs.writeFile)
const { hexToArrayBuffer, sortArrayBuffers } = require('./utils')
main()
async function main() {
const [
,
,
inputFilename,
outputFilename = `${inputFilename}.bin`,
] = process.argv
const writeStream = fs.createWriteStream(outputFilename)
console.log(`${inputFilename} -> ${outputFilename}`)
console.log(`reading...`)
const data = await read(inputFilename)
console.log('encoding...')
const addresses = data
.toString()
.trim()
.split('\n')
.map(hexToArrayBuffer)
.sort(sortArrayBuffers)
const { length } = addresses
console.log(`writing...`)
for (let i = 0; i < length; i++) {
writeStream.write(new Buffer(addresses[i]))
}
console.log('done! ✨')
}