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


TypeScript stream-buffers.ReadableStreamBuffer类代码示例

本文整理汇总了TypeScript中stream-buffers.ReadableStreamBuffer的典型用法代码示例。如果您正苦于以下问题:TypeScript ReadableStreamBuffer类的具体用法?TypeScript ReadableStreamBuffer怎么用?TypeScript ReadableStreamBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: storeImage

  public storeImage(buffer: Buffer): Promise<string> {

    const blobStream = new ReadableStreamBuffer()
    blobStream.put(buffer)
    blobStream.stop()

    const storage = gcs({
      credentials: process.env.GOOGLE_CLOUD_CREDENTIALS_JSON ? JSON.parse(process.env.GOOGLE_CLOUD_CREDENTIALS_JSON) : undefined,
      projectId: process.env.GOOGLE_CLOUD_PROJECT,
    })

    const bucketName = process.env.GOOGLE_CLOUD_BUCKET
    const bucket = storage.bucket(bucketName)
    const key = this.randomPath()
    const file = bucket.file(key)

    return new Promise<string>((resolve, reject) => {
      blobStream
      .pipe(file.createWriteStream({public: true}))
      .on("error", (err: any) => {
        reject(`Google Cloud Storage Error: ${JSON.stringify(err)}`)
      }).on("finish", () => {
        resolve(`https://storage.googleapis.com/${bucketName}/${key}`)
      })
    })

  }
开发者ID:DipJar,项目名称:looker-slackbot,代码行数:27,代码来源:google_cloud_store.ts

示例2: function

myWritableStreamBuffer.size();
myWritableStreamBuffer.maxSize();

// Gets all held data as a Buffer.
myWritableStreamBuffer.getContents();

// Gets all held data as a utf8 string.
myWritableStreamBuffer.getContentsAsString('utf8');

// Gets first 5 bytes as a Buffer.
myWritableStreamBuffer.getContents(5);

// Gets first 5 bytes as a utf8 string.
myWritableStreamBuffer.getContentsAsString('utf8', 5);

var myReadableStreamBuffer = new streamBuffers.ReadableStreamBuffer({
    frequency: 10,   // in milliseconds.
    chunkSize: 2048  // in bytes.
});

myReadableStreamBuffer.put('A String', 'utf8');
myReadableStreamBuffer.put(buffer);

myReadableStreamBuffer.on('data', function(data) {
  // streams1.x style data
  // assert.isTrue(data instanceof Buffer);
});

myReadableStreamBuffer.put('the last data this stream will ever see');
myReadableStreamBuffer.stop();
开发者ID:fullflavedave,项目名称:DefinitelyTyped,代码行数:30,代码来源:stream-buffers-tests.ts

示例3: reject

 return new Promise<string>((resolve, reject) => {
   blobStream
   .pipe(file.createWriteStream({public: true}))
   .on("error", (err: any) => {
     reject(`Google Cloud Storage Error: ${JSON.stringify(err)}`)
   }).on("finish", () => {
     resolve(`https://storage.googleapis.com/${bucketName}/${key}`)
   })
 })
开发者ID:DipJar,项目名称:looker-slackbot,代码行数:9,代码来源:google_cloud_store.ts


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