当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Readable.push方法代码示例

本文整理汇总了TypeScript中stream.Readable.push方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Readable.push方法的具体用法?TypeScript Readable.push怎么用?TypeScript Readable.push使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stream.Readable的用法示例。


在下文中一共展示了Readable.push方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: test

test('pretty no color/label/debug', () => {
  const result = pretty({ colorize: false, withLabel: false, debug: false });  
  const stream = new Readable();
  stream.push('{ "msg": "Test message", "time": 1514074545477, "level": 20, "label": "TestStream" }');
  stream.push(null);
  stream.pipe(result).pipe(process.stdout);  
});
开发者ID:HarryTmetic,项目名称:r2,代码行数:7,代码来源:pretty.test.ts

示例2: stringToStream

function stringToStream(str:string){
    var stream = new Readable();
    stream._read= ()=>{};
    stream.push(str);
    stream.push(null);
    return stream;
}
开发者ID:codecutout,项目名称:piggy-proxy,代码行数:7,代码来源:testUtils.ts

示例3: it

  it("should not throw error when given a stream", async (done) => {
    var linter: Linter = new Linter([
      new SelfCloseRule(),
    ]);

    var html = new Readable();

    html.push("<template/>");
    html.push(null);

    var result: Issue[];
    var error: Error;

    try {
      result = await linter.lint(html);
    }
    catch (err) {
      error = err;
    }
    
    expect(error).toBeUndefined();
    expect(result).toBeDefined();
    expect(result.length).toBe(1);

    done();
  });
开发者ID:atsu85,项目名称:template-lint,代码行数:26,代码来源:linter.spec.ts

示例4: test

test('tapToVSError', t => {
  const s = new stream.Readable();
  s.push(testString2);
  s.push(null);

  const w = new stream.Writable();
  let resultString = '';
  w._write = function (chunk, encoding, done) {
    //console.log('+=+' + chunk.toString());
    resultString += chunk.toString();
    done();
  };

  const option = new Options(null, 'c:/base');
  const tapToVSError = new TapToVSError(option);

  const teststream = tapToVSError.stream();
  s.pipe(teststream).pipe(w);

  w.on('finish', function () {
    console.log('resultString = ' + resultString);
    t.ok(teststream, 'teststream');
    t.ok(resultString, 'resultString');
    t.end();
  });
});
开发者ID:Quobject,项目名称:tap-to-html,代码行数:26,代码来源:index.spec.ts

示例5: writeAuthTimestamp

  private async writeAuthTimestamp(bucketAddress: string, timestamp: number): Promise<void> {

    // Recheck cache for a larger timestamp to avoid race conditions from slow storage.
    let cachedTimestamp = this.cache.get(bucketAddress)
    if (cachedTimestamp && cachedTimestamp > timestamp) {
      return
    }

    const authTimestampFileDir = this.getAuthTimestampFileDir(bucketAddress)
    
    // Convert our number to a Buffer.
    const contentBuffer = Buffer.from(timestamp.toString(), 'utf8')

    // Wrap the buffer in a stream for driver consumption.
    const contentStream = new Readable()
    contentStream.push(contentBuffer, 'utf8')
    contentStream.push(null) // Mark EOF

    await this.driver.performWrite({
      storageTopLevel: authTimestampFileDir, 
      path: AUTH_TIMESTAMP_FILE_NAME,
      stream: contentStream,
      contentLength: contentBuffer.length,
      contentType: 'text/plain; charset=UTF-8'
    })

    // In a race condition, use the newest timestamp.
    cachedTimestamp = this.cache.get(bucketAddress)
    if (cachedTimestamp && cachedTimestamp > timestamp) {
      timestamp = cachedTimestamp
    }

    this.cache.set(bucketAddress, timestamp)
  }
开发者ID:blockstack,项目名称:blockstack-registrar,代码行数:34,代码来源:revocations.ts

示例6: lint

    lint(html: string|Stream): Promise<Issue[]> {

        var parser: SAXParser = new SAXParser({ locationInfo: true });
        var parseState: ParseState = new ParseState(this.scopes, this.voids);
        
        parseState.initPreRules(parser);

        let rules = this.rules;

        rules.forEach((rule) => {
            rule.init(parser, parseState);
        });

        parseState.initPostRules(parser);

        var work:SAXParser;

        if(typeof(html) === 'string')
        {
            var stream: Readable = new Readable();
            stream.push(html);
            stream.push(null);
            work = stream.pipe(parser);
        }else if(this.isStream(html))
        {
            work = html.pipe(parser);
        }
        else{
            throw new Error("html isn't pipeable");
        }

        var completed = new Promise<void>(function (resolve, reject) {
            work.on("end", () => {
                parseState.finalise();
                resolve();
            });
        });

        var ruleTasks = [];

        rules.forEach((rule) => {
            let task = completed.then(() => {
                return rule.finalise();
            });
            ruleTasks.push(task);
        });

        return Promise.all(ruleTasks).then(results => {

            var all = new Array<Issue>();

            results.forEach(parts => {
                all = all.concat(parts);
            });

            return all;
        });
    }
开发者ID:atsu85,项目名称:template-lint,代码行数:58,代码来源:linter.ts

示例7: stringToStream

export function stringToStream(text: string): Readable | undefined {
  if (!text) {
    return undefined;
  }
  const s = new Readable();
  s.push(text);
  s.push(null);
  return s;
}
开发者ID:firebase,项目名称:firebase-tools,代码行数:9,代码来源:utils.ts

示例8: generateStream

export function generateStream(
  collections: Tyr.CollectionInstance[],
  opts: DefinitionGenerationOptions = { type: 'isomorphic' }
) {
  const stream = new Readable();
  const td = resolveGenerationMethod(opts.type)(collections, opts);
  stream.push(td);
  stream.push(null);
  return stream;
}
开发者ID:tyranid-org,项目名称:tyranid,代码行数:10,代码来源:output.ts

示例9: if

 read: () => {
     if (i === 0) {
         emitter.push(file1);
     } else if (i === 1) {
         emitter.push(file2);
     } else {
         emitter.push(null);
     }
     i++;
 }
开发者ID:winseros,项目名称:gulp-armapbo-plugin,代码行数:10,代码来源:pboTransformStream.spec.ts


注:本文中的stream.Readable.push方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。