انتقل إلى المحتوى

مرجع واجهة ⁦node:zlib⁩

كيف يدعم Elide وحدة zlib في Node: تطابق Deflate و Gzip و Brotli و Zstandard و crc32 سلوك Node، إضافة إلى امتداد المكرّرات غير المتزامنة node:zlib/iter.

اقرأ دون اتصالelide help api-node-zlib

في هذه الصفحة
الاستخدام مع الذكاء الاصطناعي
افتح في ChatGPTافتح في Claude

تدعم ⁦node:zlib⁩ واجهات دوال الاستدعاء والواجهات المتزامنة وواجهات التدفقات.

العائلةالدعم
‏⁦Deflate⁩دوال الضغط/فك الضغط المغلَّفة والخام، ومتغيرات ⁦Sync⁩، والفئات، ومساعدات ⁦create*⁩
‏⁦Gzip⁩‏⁦gzip⁩ و⁦gunzip⁩ و⁦unzip⁩، ومتغيرات ⁦Sync⁩، والفئات، ومساعدات ⁦create*⁩
‏⁦Brotli⁩دوال الضغط/فك الضغط، والفئات، ومساعدات ⁦create*⁩
‏⁦Zstandard⁩دوال الضغط/فك الضغط، والفئات، ومساعدات ⁦create*⁩
الأدوات المساعدة⁦crc32⁩ و⁦constants⁩ و⁦codes⁩
javascript
const zlib = require("node:zlib");
const input = Buffer.from("hello, zlib!");

const gzip = zlib.gzipSync(input);
zlib.gunzipSync(gzip).toString(); // "hello, zlib!"

const zstd = zlib.zstdCompressSync(input);
zlib.zstdDecompressSync(zstd).toString(); // "hello, zlib!"
utf-8 · javascript · الأسطر: 8

تتلقى صيغ دوال الاستدعاء ⁦(error, result)⁩؛ وتعيد الصيغ المتزامنة ⁦Buffer⁩ أو ترمي خطأً.

⁦node:zlib/iter⁩

توفر وحدة المكرِّرات الخاصة بـ ⁦Elide⁩ مصانع تحويل لـ ⁦gzip⁩ و⁦deflate⁩ و⁦deflate⁩ الخام و⁦Brotli⁩ و⁦Zstandard⁩. يعيد المصنع كائنًا يتضمن ⁦.transform(asyncIterable)⁩؛ وتصل المخرجات على دفعات من أجزاء البايتات.

javascript
import { gzip } from "node:zlib/iter";

async function* input() {
  yield new TextEncoder().encode("hello");
}

for await (const batch of gzip().transform(input())) {
  for (const chunk of batch) {
    // compressed bytes
  }
}
utf-8 · javascript · الأسطر: 11

استخدم تدفقات الضغط مع ⁦Web Streams⁩.

انظر أيضًا

Reference

Status: Partial · Not measured · since 1.1.0

Exports

ExportKindStatusNotes
deflateSync()functionFullCompress data using the deflate algorithm (RFC 1951 wrapped in zlib format RFC 1950)
inflateSync()functionFullDecompress data that was compressed with deflate (zlib format)
deflateRawSync()functionFullCompress data using the deflate algorithm in raw mode (no zlib header, RFC 1951)
inflateRawSync()functionFullDecompress raw deflate data (no zlib header)
gzipSync()functionFullCompress data using gzip (RFC 1952)
gunzipSync()functionFullDecompress gzip data (RFC 1952)
brotliCompressSync()functionFullCompress data using the Brotli algorithm (RFC 7932)
brotliDecompressSync()functionFullDecompress Brotli-compressed data (RFC 7932)
unzipSync()functionFullDecompress data with automatic format detection (gzip or deflate)
constantspropertyFullThe constants object exposes zlib, Brotli, and Zstd numeric constants
top-level constantsconstantPartialZ_NO_COMPRESSION, Z_BEST_SPEED, Z_BEST_COMPRESSION, Z_DEFAULT_COMPRESSION, Z_FILTERED, Z_HUFFMAN_ONLY and 73 more

Not implemented

107 top-level constants such as DEFLATE.

هل كانت هذه الصفحة مفيدة؟