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


TypeScript IncomingMessage.pipe方法代码示例

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


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

示例1: default

export default (response: IncomingMessage, options: Options, emitter: EventEmitter) => {
	const downloadBodySize = Number(response.headers['content-length']) || undefined;

	const progressStream: TransformStream = downloadProgress(response, emitter, downloadBodySize);

	mimicResponse(response, progressStream);

	const newResponse = (
		options.decompress === true &&
		is.function_(decompressResponse) &&
		options.method !== 'HEAD' ? decompressResponse(progressStream as unknown as IncomingMessage) : progressStream
	) as Response;

	if (!options.decompress && ['gzip', 'deflate', 'br'].includes(response.headers['content-encoding'] || '')) {
		options.encoding = null;
	}

	emitter.emit('response', newResponse);

	emitter.emit('downloadProgress', {
		percent: 0,
		transferred: 0,
		total: downloadBodySize
	});

	response.pipe(progressStream);
};
开发者ID:sindresorhus,项目名称:got,代码行数:27,代码来源:get-response.ts

示例2: callback

  }, (response: IncomingMessage) => {
    if (response.statusCode >= 400) {
      callback(new Error("Request error, status " + response.statusCode + ": " + response.statusMessage))
      return
    }

    const redirectUrl = response.headers.location
    if (redirectUrl != null) {
      if (redirectCount < maxRedirects) {
        doDownload(redirectUrl, destination, redirectCount++, callback)
      }
      else {
        callback(new Error("Too many redirects (> " + maxRedirects + ")"))
      }
      return
    }

    const downloadStream = createWriteStream(destination)
    response.pipe(downloadStream)
    downloadStream.on("finish", () => downloadStream.close(callback))

    let ended = false
    response.on("end", () => {
      ended = true
    })

    response.on("close", () => {
      if (!ended) {
        callback(new Error("Request aborted"))
      }
    })
  })
开发者ID:Dreadchild,项目名称:electron-builder,代码行数:32,代码来源:httpRequest.ts

示例3: createOptions

 client.fetch(url, createOptions(url), (err: Error, res: IncomingMessage) => {
   if (err) return reject(err)
   const ps = pauseStream()
   // without pausing, gunzip/tar-fs would miss the beginning of the stream
   res.pipe(ps.pause())
   resolve(ps)
 })
开发者ID:andreypopp,项目名称:pnpm,代码行数:7,代码来源:got.ts

示例4: downloadWrite

export function downloadWrite(incomingMessage:IncomingMessage, user:IUser) {
    const fullPath2Write = getDownloadFullPath(user.name);
    let file:WriteStream = fs.createWriteStream(fullPath2Write);
    incomingMessage.pipe(file);
    file.on('finish', function () {
        const ONE_K = 1024 * 1024;
        if (file.bytesWritten < ONE_K) {
            fs.unlinkSync(fullPath2Write);
        }
        file.close();
        console.log(`下载任务结束: [${user.name}]`);
        user.$isDownloading = false;
    });
}
开发者ID:jf3096,项目名称:bilibili-live-video-noty,代码行数:14,代码来源:fileSteam.ts

示例5: response

          // Handle the HTTP response.
          function response (res: IncomingMessage) {
            const status = res.statusCode
            const redirect = REDIRECT_STATUS[status]

            // Handle HTTP redirects.
            if (followRedirects && redirect != null && res.headers.location) {
              const newUrl = urlLib.resolve(url, res.headers.location)

              // Ignore the result of the response on redirect.
              res.resume()

              // Kill the old cookies on redirect.
              request.remove('Cookie')

              if (redirect === REDIRECT_TYPE.FOLLOW_WITH_GET) {
                // Update the "Content-Length" for updated redirection body.
                request.set('Content-Length', '0')

                return get(newUrl, 'GET')
              }

              if (redirect === REDIRECT_TYPE.FOLLOW_WITH_CONFIRMATION) {
                // Following HTTP spec by automatically redirecting with GET/HEAD.
                if (arg.method === 'GET' || arg.method === 'HEAD') {
                  return get(newUrl, method, body)
                }

                // Allow the user to confirm redirect according to HTTP spec.
                if (confirmRedirect(req, res)) {
                  return get(newUrl, method, body)
                }
              }
            }

            request.downloadLength = num(res.headers['content-length'], 0)

            // Track download progress.
            res.pipe(responseProxy)

            return Promise.resolve({
              body: responseProxy,
              status: status,
              statusText: res.statusMessage,
              headers: res.headers,
              rawHeaders: res.rawHeaders,
              url: url
            })
          }
开发者ID:garethhunt,项目名称:popsicle,代码行数:49,代码来源:index.ts

示例6: Promise

    return new Promise((resolve, reject)=> {
        let formData: any = {};
        let hasError: string;
        busboy.on('file', function(fieldName: string, stream: ReadableStream, filename: string, encoding: string, mimeType: string) {

            //save tmp files
            const tmpDir = (options.uploadDir ? options.uploadDir : os.tmpDir());
            const tmpPath = tmp.tmpNameSync({template: tmpDir + '/upload-XXXXXXXXXXXXXXXXXXX'});
            stream.pipe(fs.createWriteStream(tmpPath));

            stream.on('end', function() {
                //push file data
                formData[fieldName] = {
                    fileName: filename,
                    mimeType: mimeType,
                    tmpPath: tmpPath
                };
            });

            stream.on('limit', function() {
                hasError = 'filesSizeLimit';
            });
        });
        busboy.on('field', function(fieldName: string, val: any) {
            //push text data
            formData[fieldName] = val;
        });
        busboy.on('partsLimit', function() {
            hasError = 'partsLimit';
        });
        busboy.on('filesLimit', function() {
            hasError = 'filesNumberLimit';
        });
        busboy.on('fieldsLimit', function() {
            hasError = 'fieldsLimit';
        });
        busboy.on('finish', function() {
            if (hasError) {
                reject(hasError);
            } else {
                resolve(formData);
            }
        });
        req.pipe(busboy);
    });
开发者ID:sqram,项目名称:koa-async-body,代码行数:45,代码来源:index.ts

示例7: getInterval

 (response: IncomingMessage) => {
   if (options.timing) {
     if (timings.lookup === undefined) {
       timings.lookup = timings.socket;
     }
     if (timings.connect === undefined) {
       timings.connect = timings.socket;
     }
     timings.response = getInterval(startTime);
   }
   let bodyStream;
   const chunks: Buffer[] = [];
   const encoding =
     response.headers && response.headers["content-encoding"];
   if (encoding === "gzip" || encoding === "deflate") {
     response.on("error", reject);
     bodyStream = response.pipe(zlib.createUnzip());
   } else {
     bodyStream = response;
   }
   bodyStream.on("error", reject);
   bodyStream.on("data", chunk => {
     if (chunk instanceof Buffer) {
       chunks.push(chunk);
     } else {
       chunks.push(Buffer.from(chunk, "utf-8"));
     }
   });
   bodyStream.on("end", () => {
     const body = Buffer.concat(chunks).toString("utf8");
     hasRequestEnded = true;
     const serviceClientResponse = new ServiceClientResponse(
       response.statusCode || 0,
       response.headers,
       body,
       options
     );
     if (options.timing) {
       timings.end = getInterval(startTime);
       serviceClientResponse.timings = timings;
       serviceClientResponse.timingPhases = makeTimingPhases(timings);
     }
     resolve(serviceClientResponse);
   });
 }
开发者ID:zalando-incubator,项目名称:perron,代码行数:45,代码来源:request.ts

示例8:

 let request = https.get(url, (response: IncomingMessage) => {
     response.pipe(file);
     file.on("finish", () => {
         deferal.resolve();
     });
 }).on("error", (err: any) => {
开发者ID:asmundg,项目名称:gl-vsts-tasks-yarn,代码行数:6,代码来源:util.ts

示例9:

 let returnResponse = () => {
     res.setHeader('Content-Type', 'text/plain');
     res.writeHead(200);
     req.pipe(res);
 };
开发者ID:roberthardy,项目名称:rp,代码行数:5,代码来源:echoServer.ts

示例10: createWriteStream

 .then(() => {
   const downloadStream = createWriteStream(destination)
   response.pipe(downloadStream)
   downloadStream.on("finish", () => downloadStream.close(callback))
 })
开发者ID:MatthijsvandenBosch,项目名称:electron-builder,代码行数:5,代码来源:httpRequest.ts


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