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


TypeScript zlib.createInflate函数代码示例

本文整理汇总了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;未经允许,请勿转载。