• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript JSONStream.parse函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript jsontokens.decodeToken函数代码示例发布时间:2022-05-25
下一篇:
TypeScript jsonschema.Validator类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap