當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript JSONStream.parse函數代碼示例

本文整理匯總了TypeScript中JSONStream.parse函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript parse函數的具體用法?TypeScript parse怎麽用?TypeScript parse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了parse函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: request

        let go = (options: request.Options) => {
            let nextUri: string = undefined;

            if (options.uri === undefined || disposed) {
                observer.onCompleted();
            } else {
                console.log('fetching', options.uri);
                let incoming = request(options)
                    .on('error', (e: any) => observer.onError(e))
                    .on('response', (resp: IncomingMessage) => {
                        nextUri = nextLink(resp);
                        // NOTE: Only store the etag from the request to the initial URI
                        if (options.uri === initialUri) {
                            let etag = resp.headers['etag'];
                        }
                    });
                if (expr) {
                    incoming.pipe(JSONStream.parse(expr))
                        .on('error', (e: any) => observer.onError(e))
                        .on('data', (data: any) => {
                            // NOTE: Always use the initial URI as the key for cache
                            observer.onNext(data);
                        })
                        .on('end', () => go(assign({}, options, { uri: nextUri })))
                } else {
                    let chunks: any[] = [];
                    incoming
                        .on('data', (data: string) => chunks.push(data))
                        .on('end', () => {
                            observer.onNext(JSON.parse(chunks.join("")))
                            observer.onCompleted();
                        })
                }
            }
        }
開發者ID:duncanmak,項目名稱:experiments,代碼行數:35,代碼來源:retrieve.ts

示例2: exportSchema

export function exportSchema(
    db: Connection,
    { schema, pubsub }: IExportSchemaOptions
): Readable {
    const groupTables = createGroupTablesTransform(pubsub)
    const handleError = err => pubsub.emit('export-error', err)
    const sql = db.isInMemory() ? hsqlQuery : db2Query
    return db
        .createReadStream(sql, [schema])
        .on('error', handleError)
        .pipe(JSONStream.parse([true]))
        .on('error', handleError)
        .pipe(groupTables)
        .on('error', handleError)
        .pipe(JSONStream.stringify())
        .on('error', handleError)
}
開發者ID:jakobrun,項目名稱:gandalf,代碼行數:17,代碼來源:export-schema.ts

示例3: Promise

                        return new Promise((resolve, reject) => {
                            let currentResolve = resolve
                            let currentReject = reject
                            const handleError = err => currentReject(err)
                            const stream = st
                                .asStream({
                                    bufferSize: 130,
                                })
                                .on('error', handleError)
                                .pipe(JSONStream.parse([true]))
                                .on('error', handleError)

                            stream.on('data', (data: string[]) => {
                                buffer.push(data)
                                if (buffer.length >= 131) {
                                    stream.pause()
                                    currentResolve({
                                        data: buffer.splice(0, 131),
                                        more() {
                                            stream.resume()
                                            return new Promise(
                                                (resolve2, reject2) => {
                                                    currentResolve = resolve2
                                                    currentReject = reject2
                                                }
                                            )
                                        },
                                    })
                                }
                            })

                            stream.on('end', () => {
                                statement = undefined
                                currentResolve({
                                    data: buffer,
                                })
                            })
                        })
開發者ID:jakobrun,項目名稱:gandalf,代碼行數:38,代碼來源:jt400Connector.ts

示例4: dockerStream

export function dockerStream (stream: any, onFinished: (err: any, data: any) => void, onProgress: (event: any) => void) {
  var parser = JSONStream.parse(),
    output: any = [];

  parser.on('root', onStreamEvent);
  parser.on('error', onStreamError);
  parser.on('end', onStreamEnd);

  stream.pipe(parser);

  function onStreamEvent (evt: any) {
    if (!(evt instanceof Object)) {
      evt = {};
    }

    output.push(evt);

    if (evt.error) {
      return onStreamError(evt.error);
    }

    if (onProgress) {
      onProgress(evt);
    }
  }

  function onStreamError (err: any) {
    parser.removeListener('root', onStreamEvent);
    parser.removeListener('error', onStreamError);
    parser.removeListener('end', onStreamEnd);
    onFinished(err, output);
  }

  function onStreamEnd () {
    onFinished(null, output);
  }
}
開發者ID:Mercateo,項目名稱:dwatch,代碼行數:37,代碼來源:Helper.ts

示例5: extractJsonFromStream

  /**
   * Extracts json from stream, takes all the data in path. Currently only works for one `.tar.gz`-ed file.
   *
   * @param readStream
   * @param path For example "items.*" to parse only array items in a json document looking like `{name: "Example file", items: [{id: 1, id: 2}]}`
   * @param processData Function that processes each item
   */
  public async extractJsonFromStream(
    readStream: NodeJS.ReadableStream,
    path: string,
    processData: DataProcessFunction,
  ) {
    const jsonParser = JSONStream.parse(path);
    const dataProcessor = this.createDataProcessor(processData);
    const extractor = tar.extract();
    return new Promise(res => {
      extractor.on('entry', (header, stream, next) => {
        stream.pipe(jsonParser).pipe(dataProcessor);

        stream.on('end', () => {
          next(); // ready for next entry
        });

        stream.resume(); // just auto drain the stream
      });

      extractor.on('finish', res);

      readStream.pipe(gunzip()).pipe(extractor);
    });
  }
開發者ID:vnenkpet,項目名稱:japanese,代碼行數:31,代碼來源:ExtractService.ts


注:本文中的JSONStream.parse函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。