當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript zlib.gzip函數代碼示例

本文整理匯總了TypeScript中zlib.gzip函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript gzip函數的具體用法?TypeScript gzip怎麽用?TypeScript gzip使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了gzip函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: source

/**
 * Retrieve, parse and display a map source.
 */
async function source(req: Request, res: Response) {
   const key: string = req.params[RouteParam.MapSource];

   if (!is.text(key)) {
      return view.notFound(req, res);
   }

   const geo = await loadSource(key.replace('.json', ''));

   if (!is.value<MapSource>(geo)) {
      return view.notFound(req, res);
   }

   const geoText = JSON.stringify(geo);

   try {
      compress.gzip(Buffer.from(geoText), (err: Error, buffer: Buffer) => {
         if (is.value(err)) {
            view.internalError(res, err);
         } else {
            res.setHeader(Header.Content.Encoding, Encoding.GZip);
            res.setHeader(Header.CacheControl, 'max-age=86400, public'); // seconds
            res.setHeader(Header.Content.Type, addCharSet(MimeType.JSON));
            res.setHeader(
               Header.Content.Disposition,
               `attachment; filename=${key}`
            );
            res.write(buffer);
            res.end();
         }
      });
   } catch (err) {
      view.internalError(res, err);
   }
}
開發者ID:Trail-Image,項目名稱:blog,代碼行數:38,代碼來源:map.ts

示例2: reject

   new Promise<ViewItem>((resolve, reject) => {
      let text: string;
      let inferredType: MimeType;

      if (is.text(htmlOrJSON)) {
         text = htmlOrJSON;
         inferredType = MimeType.HTML;
      } else {
         text = JSON.stringify(htmlOrJSON);
         inferredType = MimeType.JSON;
      }
      if (type === undefined) {
         type = inferredType;
      }

      compress.gzip(Buffer.from(text), (err: Error, buffer: Buffer) => {
         if (is.value(err)) {
            reject(err);
            log.error(err, { slug: key });
         } else {
            resolve({
               buffer,
               eTag: key + '_' + new Date().getTime().toString(),
               type
            });
         }
      });
   });
開發者ID:Trail-Image,項目名稱:blog,代碼行數:28,代碼來源:view.ts

示例3: write

/**
 * Write contents into a compressed file.
 *
 * @async
 * @params {String} filename
 * @params {String} result
 * @params {Function} callback
 */
function write(filename: string, result: any, callback) {
    let content = JSON.stringify(result);

    return zlib.gzip(content as any, function(err, data) {
        if (err) { return callback(err); }

        return fs.writeFile(filename, data, callback);
    });
};
開發者ID:Awk34,項目名稱:awesome-typescript-loader,代碼行數:17,代碼來源:cache.ts

示例4: resGzip

function resGzip(res: any, data: any) {
	res.writeHead(200, { 'Content-Type': 'application/json', 'charset': 'utf-8', 'Content-Encoding': 'gzip' });
	
	gzip(JSON.stringify(data), (err: any, result: any) => {
		if (err) {
			console.log(err);
		}
		res.end(result);
	})
}
開發者ID:khacthanh244,項目名稱:mocha,代碼行數:10,代碼來源:index.ts

示例5: write

export function write(string, type, res) {
  zlib.gzip(string, (err, result) => {
    res.writeHead(200, {
      'Content-Length': result.length,
      'Content-Type': type,
      'Content-Encoding': 'gzip'
    })
    res.write(result)
    res.end()
  });
}
開發者ID:djeeg,項目名稱:example-react-router-universal-lazyroutes-typescript,代碼行數:11,代碼來源:server-utils.ts

示例6:

    s.on('/', (req, res) => {
        res.statusCode = 200;
        res.setHeader('Content-Type', 'text/plain');
        res.setHeader('Content-Encoding', 'gzip');

        if (req.method === 'HEAD') {
            res.end();
            return;
        }

        zlib.gzip(testContent, (_, data) => res.end(data));
    });
開發者ID:cyounkins,項目名稱:typed-got,代碼行數:12,代碼來源:gzip.ts

示例7: promiseTo

 const gzippedJson = await promiseTo(cb => zlib.gzip(json as any as Buffer, cb));
開發者ID:convoyinc,項目名稱:apollo-server,代碼行數:1,代碼來源:apolloServerHttp.test.ts

示例8: deflateRaw

        result, { finishFlush: constants.Z_SYNC_FLUSH },
        (err: Error | null, result: Buffer) => result
    )
);
deflateRaw(compressMeString, (err: Error | null, result: Buffer) => inflateRaw(result, (err: Error | null, result: Buffer) => result));
deflateRaw(
    compressMeString,
    { finishFlush: constants.Z_SYNC_FLUSH },
    (err: Error | null, result: Buffer) => inflateRaw(result, { finishFlush: constants.Z_SYNC_FLUSH }, (err: Error | null, result: Buffer) => result),
);
const inflatedRaw: Buffer = inflateRawSync(deflateRawSync(compressMe));
const inflatedRawString: Buffer = inflateRawSync(deflateRawSync(compressMeString));

// gzip

gzip(compressMe, (err: Error | null, result: Buffer) => gunzip(result, (err: Error | null, result: Buffer) => result));
gzip(
    compressMe,
    { finishFlush: constants.Z_SYNC_FLUSH },
    (err: Error | null, result: Buffer) => gunzip(
        result, { finishFlush: constants.Z_SYNC_FLUSH },
        (err: Error | null, result: Buffer) => result
    )
);
const gunzipped: Buffer = gunzipSync(gzipSync(compressMe));

unzip(compressMe, (err: Error | null, result: Buffer) => result);
unzip(compressMe, { finishFlush: constants.Z_SYNC_FLUSH }, (err: Error | null, result: Buffer) => result);
const unzipped: Buffer = unzipSync(compressMe);

const bOpts: BrotliOptions = {
開發者ID:CNBoland,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:zlib.ts

示例9: Promise

 const zipped = await new Promise(resolve => zlib.gzip(moduleBuffer, (_, result) => resolve(result)));
開發者ID:electron,項目名稱:electron-rebuild,代碼行數:1,代碼來源:cache.ts


注:本文中的zlib.gzip函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。