mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2024-11-25 09:27:28 +00:00
Use get-stream instead of reading by hand
This commit is contained in:
parent
b4d21f5002
commit
bfc8a1443f
1
package-lock.json
generated
1
package-lock.json
generated
@ -1803,7 +1803,6 @@
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.1.0.tgz",
|
||||
"integrity": "sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"pump": "^3.0.0"
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
"better-sqlite3": "^6.0.1",
|
||||
"cookie": "^0.4.1",
|
||||
"feed": "github:cloudrac3r/feed#f42b4d7183fc2b6e566cb400ad083c4dd714c858",
|
||||
"get-stream": "^5.1.0",
|
||||
"mixin-deep": "^2.0.1",
|
||||
"node-dir": "^0.1.17",
|
||||
"node-fetch": "^2.6.0",
|
||||
|
@ -1,7 +1,7 @@
|
||||
const fs = require("fs")
|
||||
const {createGunzip} = require("zlib")
|
||||
const pj = require("path").join
|
||||
const db = require("../src/lib/db")
|
||||
const getStream = require("get-stream")
|
||||
const {request} = require("../src/lib/utils/request")
|
||||
|
||||
async function progress(message, callback) {
|
||||
@ -42,10 +42,7 @@ async function progress(message, callback) {
|
||||
// Read out the stream into a buffer
|
||||
/** @type {{username: string, user_id: string, created: number, updated: number, updated_version: number, biography: string, post_count: number, following_count: number, followed_by_count: number, external_url: string, full_name: string, is_private: number, is_verified: number, profile_pic_url: string}[]} */
|
||||
const incomingUsers = await progress("Reading data... ", async () => {
|
||||
const buffers = []
|
||||
usersStream.on("data", chunk => buffers.push(chunk))
|
||||
await new Promise(resolve => usersStream.once("end", resolve))
|
||||
const usersString = Buffer.concat(buffers).toString("utf8")
|
||||
const usersString = await getStream(usersStream, {encoding: "utf8"})
|
||||
return JSON.parse(usersString)
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user