當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。