{"library":"osm-pbf-parser","title":"OpenStreetMap PBF Streaming Parser","description":"osm-pbf-parser is a Node.js library designed for streaming parsing of OpenStreetMap Protocol Buffer (PBF) files. It processes binary PBF data, converting it into a stream of JavaScript objects representing OSM nodes, ways, and relations. The current stable version is 2.3.0. This library is designed for handling large `.pbf` files efficiently by processing them in a streaming fashion, avoiding the need to load the entire file into memory. It further differentiates itself by exposing `BlobParser` and `BlobEncoder` components, which allow for distributing binary work units and facilitating parallel processing of PBF data blobs, a feature useful for high-performance data extraction and transformation workflows. Due to its age (last updated in 2021) and CommonJS-only nature, it should be considered for projects that can tolerate an unmaintained dependency or require its specific streaming and parallel processing features for older Node.js environments.","language":"javascript","status":"abandoned","last_verified":"Sun Apr 19","install":{"commands":["npm install osm-pbf-parser"],"cli":null},"imports":["const parseOSM = require('osm-pbf-parser');","const { BlobParser } = require('osm-pbf-parser');","const { BlobEncoder } = require('osm-pbf-parser');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const fs = require('fs');\nconst through = require('through2');\nconst parseOSM = require('osm-pbf-parser');\n\n// To run, save a .pbf file (e.g., 'denmark-latest.osm.pbf')\n// and execute with: node your_parser.js denmark-latest.osm.pbf\n\nconst filePath = process.argv[2];\n\nif (!filePath) {\n    console.error('Usage: node parser.js <path_to_osm.pbf_file>');\n    process.exit(1);\n}\n\nconst osmStream = parseOSM();\n\nfs.createReadStream(filePath)\n    .pipe(osmStream)\n    .pipe(through.obj(function (items, enc, next) {\n        items.forEach(function (item) {\n            // Each item is an OSM node, way, or relation object\n            console.log(`Type: ${item.type}, ID: ${item.id}, Tags:`, item.tags);\n        });\n        next();\n    }))\n    .on('finish', () => {\n        console.log('Finished parsing PBF file.');\n    })\n    .on('error', (err) => {\n        console.error('Error during parsing:', err);\n    });\n","lang":"javascript","description":"Demonstrates streaming parsing of an OpenStreetMap PBF file, logging the type, ID, and tags of each item (node, way, or relation) to the console.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}