Skip to content

Instantly share code, notes, and snippets.

@bpsushi
Created March 18, 2024 11:58
Show Gist options
  • Select an option

  • Save bpsushi/201669faa4b08aaac2ed1d4c0079d588 to your computer and use it in GitHub Desktop.

Select an option

Save bpsushi/201669faa4b08aaac2ed1d4c0079d588 to your computer and use it in GitHub Desktop.
Process gzip json files as streams
/**
* Example JSON
*/
//{
// "books": [
// { "title": "The Witcher - The Last Wish" },
// { "title": "The Witcher - Sword of Destiny" },
// { "title": "The Witcher - Blood of Elves" },
// ]
//}
const https = require("node:https");
const Zlib = require("node:zlib");
const JSONStream = require("jsonstream");
https
.get(
"https://SOME_DOMAIN/my_file.json.gz",
(res) => {
res
.pipe(Zlib.createGunzip())
.pipe(JSONStream.parse("books.*"))
.on("data", (chunk) => {
console.log("data chunk", chunk);
});
res.on("end", () => {
console.log("stream end");
});
}
)
.on("error", (err) => console.log("Error:" + err.message, err));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment