Adding stream-json tools

This commit is contained in:
2021-05-19 08:16:47 -07:00
parent a608bc5f51
commit 1fb44c31f0
4 changed files with 36 additions and 16 deletions

View File

@@ -3,7 +3,7 @@ import { Context, Service, ServiceBroker, ServiceSchema } from "moleculer";
import fs from "fs";
import { DbMixin } from "../mixins/db.mixin";
import Comic from "../models/comic.model";
import { map, flatten } from "lodash";
import { map, flatten, isUndefined } from "lodash";
import {
extractArchive,
getCovers,
@@ -21,6 +21,11 @@ import H from "highland";
import { stringify } from "highland-json";
const IO = require("socket.io")();
const { parser } = require("stream-json");
const { pick } = require("stream-json/filters/Pick");
const { ignore } = require("stream-json/filters/Ignore");
const { streamValues } = require("stream-json/streamers/StreamValues");
export default class ProductsService extends Service {
// @ts-ignore
public constructor(
@@ -74,18 +79,24 @@ export default class ProductsService extends Service {
ctx.params.extractionOptions.extractionMode
) {
case "bulk":
let rs = new Readable();
const extractedDataPromises = map(
ctx.params.walkedFolders,
async (folder) =>
await extractArchive(
ctx.params
.extractionOptions,
folder
)
async (folder) => {
while (!isUndefined(folder)) {
let foo =
await extractArchive(
ctx.params
.extractionOptions,
folder
);
console.log("levar", foo);
rs.push(foo);
}
rs.push(null);
}
);
return Promise.all(
extractedDataPromises
).then((data) => flatten(data));
case "single":
return await extractArchive(
ctx.params.extractionOptions,