• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript zlib.createInflate函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: switch

			let request = http.request(options, (response: Server.IRequestResponseData) => {
				let data: string[] = [];
				let isRedirect = helpers.isResponseRedirect(response);
				let successful = helpers.isRequestSuccessful(response);
				if (!successful) {
					pipeTo = undefined;
				}

				let responseStream = response;
				switch (response.headers["content-encoding"]) {
					case "gzip":
						responseStream = responseStream.pipe(zlib.createGunzip());
						break;
					case "deflate":
						responseStream = responseStream.pipe(zlib.createInflate());
						break;
				}

				if (pipeTo) {
					pipeTo.on("finish", () => {
						this.$logger.trace("httpRequest: Piping done. code = %d", response.statusCode.toString());
						if(!result.isResolved()) {
							result.return({
								response: response,
								headers: response.headers
							});
						}
					});

					pipeTo = this.trackDownloadProgress(pipeTo);

					responseStream.pipe(pipeTo);
				} else {
					responseStream.on("data", (chunk: string) => {
						data.push(chunk);
					});

					responseStream.on("end", () => {
						this.$logger.trace("httpRequest: Done. code = %d", response.statusCode.toString());
						let responseBody = data.join("");

						if (successful || isRedirect) {
							if(!result.isResolved()) {
								result.return({
									body: responseBody,
									response: response,
									headers: response.headers
								});
							}
						} else {
							let errorMessage = this.getErrorMessage(response, responseBody);
							let theError: any = new Error(errorMessage);
							theError.response = response;
							theError.body = responseBody;
							result.throw(theError);
						}
					});
				}
			});
开发者ID:enchev,项目名称:mobile-cli-lib,代码行数:59,代码来源:http-client.ts


示例2: getContentStream

function getContentStream(stream: Readable, headers: RequestHeaders): Maybe<Readable> {
  const ce = String(headers['content-encoding'] || 'identity').toLowerCase();

  return ce === 'identity' ? just(stream)
    : ce === 'gzip' ? just(stream.pipe(createGunzip()))
      : ce === 'deflate' ? just(stream.pipe(createInflate()))
        : nothing;
}
开发者ID:syaiful6,项目名称:jonggrang,代码行数:8,代码来源:parser.ts


示例3: function

 }, function (err, res) {
   if (err) return callback(err);
   if (!res) return callback(new Error('Response should not be undefined if there is no error.'));
   const newHeaders = ({...res.headers} as any);
   let newBody = res.body;
   switch (newHeaders['content-encoding']) {
     case 'gzip':
       delete newHeaders['content-encoding'];
       newBody = res.body.pipe(createGunzip());
       break;
     case 'deflate':
       delete newHeaders['content-encoding'];
       newBody = res.body.pipe(createInflate());
       break;
   }
   return callback(err, new Response(res.statusCode, newHeaders, newBody, res.url));
 });
开发者ID:ForbesLindesay,项目名称:http-basic,代码行数:17,代码来源:index.ts


示例4:

	'deflate': (req: NodeJS.ReadableStream) => req.pipe(zlib.createInflate()),
开发者ID:charto,项目名称:csrv,代码行数:1,代码来源:parseQuery.ts


示例5: listener

export function listener(httpRequest, httpResponse): void {
  stats.totalRequests += 1;

  if (httpRequest.method !== "POST") {
    httpResponse.writeHead(405, {
      Allow: "POST",
      Connection: "close"
    });
    httpResponse.end("405 Method Not Allowed");
    return;
  }

  let sessionId;
  // Separation by comma is important as some devices don't comform to standard
  const COOKIE_REGEX = /\s*([a-zA-Z0-9\-_]+?)\s*=\s*"?([a-zA-Z0-9\-_]*?)"?\s*(,|;|$)/g;
  let match;
  while ((match = COOKIE_REGEX.exec(httpRequest.headers.cookie)))
    if (match[1] === "session") sessionId = match[2];

  // If overloaded, ask CPE to retry in 60 seconds
  if (!sessionId && stats.concurrentRequests > MAX_CONCURRENT_REQUESTS) {
    httpResponse.writeHead(503, {
      "Retry-after": 60,
      Connection: "close"
    });
    httpResponse.end("503 Service Unavailable");
    stats.droppedRequests += 1;
    return;
  }

  let stream = httpRequest;
  if (httpRequest.headers["content-encoding"]) {
    switch (httpRequest.headers["content-encoding"]) {
      case "gzip":
        stream = httpRequest.pipe(zlib.createGunzip());
        break;
      case "deflate":
        stream = httpRequest.pipe(zlib.createInflate());
        break;
      default:
        httpResponse.writeHead(415, { Connection: "close" });
        httpResponse.end("415 Unsupported Media Type");
        return;
    }
  }

  stats.concurrentRequests += 1;
  httpRequest.on("aborted", () => {
    stats.concurrentRequests -= 1;
    // In some cases event end can be emitted after aborted event
    httpRequest.removeAllListeners("end");
  });

  const chunks = [];
  let bytes = 0;
  stream.on("data", chunk => {
    chunks.push(chunk);
    bytes += chunk.length;
  });

  stream.on("end", () => {
    const body = Buffer.allocUnsafe(bytes);
    let offset = 0;
    for (const chunk of chunks) {
      chunk.copy(body, offset, 0, chunk.length);
      offset += chunk.length;
    }

    function parsedRpc(sessionContext, rpc, parseWarnings): void {
      for (const w of parseWarnings) {
        w.sessionContext = sessionContext;
        w.rpc = rpc;
        logger.accessWarn(w);
      }

      if (sessionContext.debug) {
        const dump =
          `# REQUEST ${new Date(Date.now())}\n` +
          JSON.stringify(httpRequest.headers) +
          "\n" +
          body +
          "\n\n";
        fs.appendFile(`./debug/${sessionContext.deviceId}.dump`, dump, err => {
          if (err) return void throwError(err);
        });
      }

      processRequest(sessionContext, rpc);
    }

    getSession(httpRequest.connection, sessionId, (err, sessionContext) => {
      if (err) return void throwError(err, httpResponse);

      if (sessionContext) {
        sessionContext.httpRequest = httpRequest;
        sessionContext.httpResponse = httpResponse;
        if (
          sessionContext.sessionId !== sessionId ||
          sessionContext.lastActivity + sessionContext.timeout * 1000 <
            Date.now()
//.........这里部分代码省略.........
开发者ID:zaidka,项目名称:genieacs,代码行数:101,代码来源:cwmp.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript zlib.deflate函数代码示例发布时间:2022-05-25
下一篇:
TypeScript zlib.createGzip函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap