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