-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbz2-block-reader0.js
More file actions
executable file
·37 lines (31 loc) · 1.07 KB
/
Copy pathbz2-block-reader0.js
File metadata and controls
executable file
·37 lines (31 loc) · 1.07 KB
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
36
37
var fs = require('fs');
var path = require('path');
var SeekBzip = require('@arijs/seek-bzip');
var dataSize = require('./datasize');
function printCRC(crc) {
return ('00000000'+crc.toString(16)).substr(-8, 8);
}
var fpath = path.resolve(__dirname, '../planet-latest.osm.bz2');
var fstat = fs.statSync(fpath);
var fd = fs.openSync(fpath, 'r');
var tstart = Date.now();
var fopt;
function outPrint(buf) {
if (buf.length <= 1024) {
console.log(buf.toString('utf8'));
}
}
console.log(dataSize(fstat.size));
try {
do {
fopt = SeekBzip.readBlock(fd, fopt, null, 131072);
if (fopt.streamCRC) {
console.log(' '+fopt.fileCount+' file '+(fopt.fileOffset)+' bit '+fopt.bitOffsetEnd+' in '+(fopt.bytesInput)+' crc '+printCRC(fopt.streamCRC));
} else if (fopt.blockCRC) {
console.log(fopt.fileCount+'.'+fopt.blockCount+' block '+(fopt.byteOffset)+' bit '+fopt.bitOffset+' in '+(fopt.bytesInput)+' out '+(fopt.bytesOutput)+' crc '+printCRC(fopt.blockCRC));
fopt.swrite.flush();
}
} while (fopt.fileOffset < fstat.size);
} finally {
fs.closeSync(fd);
}