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