エンコード
Gzip/Deflate ↔ Base64
テキストを Gzip または Deflate で圧縮し、結果を Base64 でエンコード — その逆も可能。Compression Streams API を使いブラウザ内で完結。
Base64 by itself doesn't compress anything — quite the opposite, it grows the size by about 33%. To send large text compactly through a text-only channel, it's first compressed with Gzip or Deflate, and only then is the result Base64-encoded.
How to use it
- Compress: paste text and the tool compresses it with Gzip or Deflate (the browser's Compression Streams API) and encodes the result as Base64.
- Decompress: paste a Base64 string of compressed content to get the original text back.
- Pick Gzip or Deflate depending on which format the receiving system expects.
Common uses
- Compactly embedding a large text value (an SVG, a config) in a URL parameter or cookie with a size limit.
- Preparing a compressed payload for an API that accepts Base64-encoded Gzip data.
- Decompressing data received in this format from another system so it can be read manually.
Things to keep in mind
Compression only pays off on sufficiently large, compressible text — on short strings the Gzip header overhead plus the Base64 expansion can actually make the result bigger.
Deflate skips Gzip's headers, so its output is more compact, but the format is less self-describing: the receiving side needs to know in advance that it's Deflate specifically.
よくある質問
Gzip と Deflate の違いは何ですか?
Deflateは圧縮アルゴリズム自体を指し、Gzipはそのdeflateデータにヘッダーとチェックサム(CRC)を付加したフォーマットです。同じ圧縮アルゴリズムを使っていても、データの先頭に付く情報が異なるため互換性はありません。
エンコード後のデータが元より大きくなることはありますか?
あります。特に短いテキストの場合、圧縮によるヘッダーやメタデータのオーバーヘッドがデータ削減分を上回り、Base64エンコードも加わることでかえって元のテキストより大きくなることがあります。
入力したテキストはサーバーに送信されますか?
いいえ、圧縮・伸長・Base64変換はすべてブラウザのCompression Streams APIを使ってブラウザ内で完結しており、外部に送信されることはありません。
なぜ展開時に「invalid header」エラーが出ることがあるのですか?
最もよくある原因はフォーマットの取り違えです。ヘッダーのない「生の」Deflateとして圧縮されたデータを、独自のヘッダーとCRC-32を期待するGzipとして展開しようとしている(あるいはその逆)場合に起こります。ツールの設定でフォーマットを切り替えてみてください。
圧縮すれば必ず最終的なサイズは小さくなりますか?
いいえ。非常に短い文字列では、Gzipヘッダーのオーバーヘッドとその後のBase64による増加分が圧縮の効果を上回ることがあります。この手法は、十分に大きく圧縮しやすいテキストデータでのみ意味があります。