How to use the stream-json/streamers/StreamValues.withParser function in stream-json

To help you get started, we’ve selected a few stream-json examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lifeomic / cli / lib / commands / fhir.js View on Github external
async function ingest (options) {
  let resources = [];

  const pipeline = stdin().pipe(StreamValues.withParser());

  return new Promise((resolve, reject) => {
    pipeline.on('data', async ({ value }) => {
      if (Array.isArray(value)) {
        resources = resources.concat(value);
      } else {
        resources.push(value);
      }

      if (resources.length >= options.chunk) {
        try {
          const payload = resources.slice();
          resources = [];
          await batchUpload(options, payload);
        } catch (err) {
          pipeline.destroy(err);
github electron-userland / electron-builder / packages / electron-builder-lib / src / remoteBuilder / RemoteBuildManager.ts View on Github external
stream.on("response", headers => {
        const status: number = headers[HTTP2_HEADER_STATUS] as any
        if (status !== HTTP_STATUS_OK) {
          reject(new HttpError(status))
          return
        }

        stream.pipe(StreamValues.withParser())
          .on("data", (object: any) => {
            const data = object.value
            if (log.isDebugEnabled) {
              log.debug({event: JSON.stringify(data, null, 2)}, "remote builder event")
            }

            if (data.status != null) {
              log.info({status: data.status}, "remote building")
            }
            else if ("error" in data) {
              resolve({files: null, error: data.error})
            }
            else if ("files" in data) {
              this.downloadArtifacts(data.files, data.fileSizes, data.baseUrl)
                .then(() => {
                  stream.destroy()

stream-json

stream-json is the micro-library of Node.js stream components for creating custom JSON processing pipelines with a minimal memory footprint. It can parse JSON files far exceeding available memory streaming individual primitives using a SAX-inspired API. I

BSD-3-Clause
Latest version published 9 days ago

Package Health Score

80 / 100
Full package analysis