การเข้ารหัส
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 + Base64: บีบอัดข้อมูลเพื่อส่งเป็นข้อความ
คำถามที่พบบ่อย
Gzip กับ Deflate ในเครื่องมือนี้ต่างกันอย่างไร?
Gzip ห่อข้อมูลที่บีบอัดด้วยส่วนหัวและค่าตรวจสอบ CRC ท้ายไฟล์ ส่วน Deflate คือกระแสข้อมูลบีบอัดดิบที่ไม่มีส่วนห่อนั้น ข้อมูลที่บีบอัดด้วยรูปแบบหนึ่งจะถอดด้วยอีกรูปแบบไม่ได้ — ตรวจสอบให้แน่ใจว่ารูปแบบที่เลือกตรงกับวิธีสร้างข้อมูลนั้น
ทำไมต้องเข้ารหัส Base64 ข้อมูลที่บีบอัดแล้ว?
ผลลัพธ์ของ Gzip/Deflate เป็นไบนารีดิบ ซึ่งอยู่ในบริบทข้อความอย่าง URL, JSON หรือไฟล์คอนฟิกได้ไม่ดี การเข้ารหัส Base64 จะเปลี่ยนข้อมูลไบนารีนั้นให้เป็นข้อความ ASCII ที่ปลอดภัยและคัดลอกได้
ทำไมเครื่องมือบอกว่าเบราว์เซอร์ของฉันไม่รองรับ?
เครื่องมือนี้ใช้ Compression Streams API ของเบราว์เซอร์ (CompressionStream/DecompressionStream) ซึ่งไม่มีในเบราว์เซอร์หรือเวอร์ชันเก่าบางตัว — ไม่มีข้อมูลใดถูกส่งไปเซิร์ฟเวอร์ แต่หากไม่รองรับเครื่องมือก็จะทำงานไม่ได้
ทำไมการคลายข้อมูลบางครั้งจึงเกิดข้อผิดพลาด "invalid header"?
สาเหตุที่พบบ่อยที่สุดคือรูปแบบสับสนกัน: ข้อมูลถูกบีบอัดเป็น Deflate แบบ "ดิบ" ที่ไม่มีส่วนหัว แต่ถูกคลายในโหมด Gzip (ซึ่งคาดหวังส่วนหัวและ CRC-32 ของตัวเอง) หรือในทางกลับกัน ลองสลับรูปแบบในตัวเลือกของเครื่องมือดู
การบีบอัดทำให้ขนาดสุดท้ายเล็กลงเสมอหรือไม่?
ไม่เสมอไป สำหรับสตริงที่สั้นมาก ค่าใช้จ่ายของส่วนหัว Gzip และการขยายขนาดจาก Base64 อาจมากกว่าประโยชน์จากการบีบอัด วิธีนี้เหมาะกับข้อมูลข้อความที่มีขนาดใหญ่พอและบีบอัดได้ดีเท่านั้น