Skip to content

Instantly share code, notes, and snippets.

@yoheiMune
Last active August 29, 2015 14:07
Show Gist options
  • Save yoheiMune/461ec999b2cf149a875c to your computer and use it in GitHub Desktop.
Save yoheiMune/461ec999b2cf149a875c to your computer and use it in GitHub Desktop.
Gzip and Gunzip with Node
var fs = require('fs');
var zlib = require('zlib');
// ファイルを読み込みます
var gzipContent = fs.readFileSync('./hello.txt.gz');
// 解凍します
zlib.gunzip(gzipContent, function (err, binary) {
// ファイルに出力します
fs.writeFileSync('./hello2.txt', binary);
// Node上で解凍結果を文字列として扱う場合には、
// 文字列への変換を行います
var string = binary.toString('utf-8');
console.log(string);
});
var fs = require('fs');
var zlib = require('zlib');
// ファイルを読み込みます
var content = fs.readFileSync('./hello.txt');
// Gzipを行います
zlib.gzip(content, function (err, binary) {
// 結果をファイルシステムに書き込みます
fs.writeFileSync('./hello.txt.gz', binary);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment