Last active
August 29, 2015 14:07
-
-
Save yoheiMune/461ec999b2cf149a875c to your computer and use it in GitHub Desktop.
Gzip and Gunzip with Node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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