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