本文整理汇总了TypeScript中zlib.createGunzip函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createGunzip函数的具体用法?TypeScript createGunzip怎么用?TypeScript createGunzip使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createGunzip函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
});
}
});
示例2: unTarGz
private async unTarGz(zipLocation: string, unzipLocation: string): Promise<void> {
return Promise.resolve(
fs
.createReadStream(zipLocation)
.pipe(zlib.createGunzip())
.pipe(tar.extract(unzipLocation))
);
}
示例3: fromFileSync
export function fromFileSync(filename:string) : NiftiStream {
accessSync(filename, R_OK);
let stream:NodeJS.ReadableStream = createReadStream(filename);
if (filename.substr(-'.gz'.length) === '.gz') {
stream = stream.pipe(createGunzip());
}
return new NiftiStream(stream);
}
示例4: 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;
}
示例5: asyncTest
asyncTest("gzip roundtrip", 1, (_) => {
const sampleReader1 = ez.devices.file.text.reader(sample);
var sampleReader2 = ez.devices.file.text.reader(sample);
const stringify = ez.mappers.convert.stringify();
const cutter = ez.transforms.cut.transform(10);
const out = require('fs').createWriteStream(__dirname + '/../../test/fixtures/rss-sample.zip');
sampleReader2 = sampleReader2.nodeTransform(zlib.createGzip()).nodeTransform(zlib.createGunzip()).map(stringify);
const cmp = sampleReader1.transform(cutter).compare(_, sampleReader2.transform(cutter));
equal(cmp, 0);
start();
});
示例6: access
access(filename, R_OK, function(err) {
if (err) {
callback(err, null);
return;
}
let stream:NodeJS.ReadableStream = createReadStream(filename);
if (filename.substr(-'.gz'.length) === '.gz') {
stream = stream.pipe(createGunzip());
}
callback(null, new NiftiStream(stream));
});
示例7: resolve
http.get({...requestOptions, headers: {'Accept-Encoding': 'compress, gzip', sig: type.getSignature()}}, res => {
try {
resolve(
promisify(io.readValue)({type, inStream: res.pipe(zlib.createGunzip())})
.then(value =>
assert.deepEqual(value, responseValue)
)
)
}
catch (e) { reject(e) }
})
示例8: Buffer
conn.query(q, args, (qerr, results) => {
conn.release();
if (qerr) {
console.log('Error validating file id', qerr);
return res.status(500).send({ Error: 'Internal Server Error' });
}
if (results.length < 1) {
return res.status(404).send({ Error: 'No such file ID' });
}
const decipher = crypto.createDecipher('aes256', new Buffer(APP_CONFIG.storage_key, 'base64'));
store.get(fileid).pipe(decipher).pipe(zlib.createGunzip()).pipe(res).once('close', () => res.end());
});
示例9: before
before(function(done) {
this.timeout(TIMEOUT);
console.log(
"Loading in complete array of postcodes (this might take a while)..."
);
const inputFile = resolve(__dirname, "./data/postcodes.csv.gz");
createReadStream(inputFile)
.pipe(createGunzip())
.pipe(parse({ delimiter: "," }))
.on("data", (data: CsvRecord) => testData.push(data[0]))
.on("error", done)
.on("end", done);
});