10
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

node.jsによるzlib圧縮/伸長

Last updated at Posted at 2013-11-07

node.jsによるzlib圧縮/伸長

sample_zlib.js
// node v0.10.21

"use strict";

var zlib   = require('zlib');
var uncipherd_text = 'ひらぶん';

console.log("source");
console.log(uncipherd_text);

// 圧縮
console.log('deflate');
zlib.deflate(uncipherd_text, function(err, buffer) {
  if (err) {
    console.log(err);
    return;
  }

  console.log(buffer);
  
  // 伸長
  zlib.unzip(buffer, function(err, buffer) {
    if (err) {
      console.log(err);
      return;
    }
    
    console.log('unzip');
    console.log(buffer.toString());
  });
});

実行結果

> source
> ひらぶん
> ziped
> <Buffer 78 9c 7b dc b8 e9 71 53 e7 e3 c6 6d 8f 9b 26 03 00 35 e8 08 17>
> unzip
> ひらぶん
10
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?