marook / osm-read

an openstreetmap XML and PBF data parser for node.js and the browser
GNU Lesser General Public License v3.0
107 stars 25 forks source link

pbfParser in node.js and "TypeError: Invalid non-string/buffer chunk" #38

Open rhz opened 5 years ago

rhz commented 5 years ago

Has anyone been able to use osm-read-pbf from node.js? By using the same code I was running successfully in the browser I get a "TypeError: Invalid non-string/buffer chunk" before any nodes, ways or relations are read (ie probably right after it starts reading the pbf file). If needed I can upload the pbf file I'm using but I'm guessing the problem is already there with example/test.pbf.

marook commented 5 years ago

Are you using the current master branch? There are some issues in it. Have you tried v0.6.0 ( https://github.com/marook/osm-read/releases/tag/v0.6.0 )?

If v0.6.0 does not work for you it would be interesting which node.js version you are using?

rhz commented 5 years ago

I'm using v0.6.0. I installed it using npm. I'm using nodejs v8.15.0.

rhz commented 5 years ago

I updated nodejs to v11.6.0 and it's working now :)

marook commented 5 years ago

cool :)

rhz commented 5 years ago

I now get a different error

fs.js:143
    throw new ERR_INVALID_CALLBACK();
    ^

TypeError [ERR_INVALID_CALLBACK]: Callback must be a function
    at makeCallback (fs.js:143:11)
    at Object.close (fs.js:401:20)
    at Object.close (/home/rhz/research/cinv/tsunami/engine/node_modules/osm-read/osm-read-pbf.js:10:624)
    at Object.n.close (/home/rhz/research/cinv/tsunami/engine/node_modules/osm-read/osm-read-pbf.js:14:655)
    at s (/home/rhz/research/cinv/tsunami/engine/node_modules/osm-read/osm-read-pbf.js:14:300)
    at /home/rhz/research/cinv/tsunami/engine/node_modules/osm-read/osm-read-pbf.js:14:418
    at Object.readPBFElementFromBuffer (/home/rhz/research/cinv/tsunami/engine/node_modules/osm-read/osm-read-pbf.js:8:49)
    at Inflate.cb (/home/rhz/research/cinv/tsunami/engine/node_modules/osm-read/osm-read-pbf.js:14:5413)
    at Inflate.zlibBufferOnEnd (zlib.js:124:10)
    at Inflate.emit (events.js:193:15)

Any ideas?

rhz commented 5 years ago

By running the project using ndb I see a call to parser.close() without giving any callback to the function (line 66 of pbfParser.js). Could this be the source of the issue?

rhz commented 5 years ago

Should I open a new issue with this error or is it ok to continue here?

rhz commented 5 years ago

The problem was indeed in that line. I replaced parser.close() by parser.close(() => {}) and it's working now. Also, I cloned the repo and I'm importing the library directly from lib/pbfParser.js instead of using the version produced by browserify, not sure if that makes a difference. I'll leave the issue open in the hope that it gets fixed in a v0.6.1 branch and published to npm :)

rhz commented 5 years ago

Any news on this?