feat: require fs
This commit is contained in:
parent
30edb85fe8
commit
48eedb3d64
25
pbf/index.js
25
pbf/index.js
|
@ -1,3 +1,4 @@
|
|||
const fs = require('fs');
|
||||
const debug=require('debug')('pbf');
|
||||
const gtfsRt=require('../../proto2js/js/gtfs-rt.js');
|
||||
const Pbf = require('pbf');
|
||||
|
@ -10,12 +11,22 @@ run().catch(err => {
|
|||
async function run() {
|
||||
debug('run started...');
|
||||
const FeedMessage = gtfsRt.FeedMessage;
|
||||
const buffer=[];
|
||||
// read
|
||||
debug('create pbf');
|
||||
const pbf = new Pbf(buffer);
|
||||
debug('create obj');
|
||||
const obj = FeedMessage.read(pbf);
|
||||
debug('use obj');
|
||||
debug('read gtfs-rt feed from file');
|
||||
const buffer=fs.readFileSync('/tmp/gtfsr_connect.bin');
|
||||
if(buffer instanceof Buffer){
|
||||
debug('buffer is instance of Buffer');
|
||||
debug('read buffer and create pbf');
|
||||
const pbf = new Pbf(buffer);
|
||||
debug('create obj');
|
||||
const obj = FeedMessage.read(pbf);
|
||||
debug('use obj');
|
||||
if(obj.header in obj){
|
||||
debug('obj has header');
|
||||
}else{
|
||||
debug('obj has header NOT');
|
||||
}
|
||||
}else{
|
||||
debug('buffer is NOT instance of Buffer');
|
||||
}
|
||||
debug('run done.');
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
"nodemon": "^2.0.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"fs": "^0.0.1-security",
|
||||
"pbf": "^3.2.1"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue