// Auto-generated by scripts/gen_parity_tests.py from docs/runtime-parity.md.
// Module: node:zlib
// This file is a byte-for-byte parity test against `node --experimental-strip-types`.
// Edit the TODO lines below to exercise each API; rerun
// `./run_parity_tests.sh --filter test_parity_zlib` to verify.

import * as zlib from "node:zlib";


// ── Classes ──
console.log("zlib.Deflate typeof:", typeof zlib.Deflate);
console.log("zlib.DeflateRaw typeof:", typeof zlib.DeflateRaw);
console.log("zlib.Gzip typeof:", typeof zlib.Gzip);
console.log("zlib.Gunzip typeof:", typeof zlib.Gunzip);
console.log("zlib.Inflate typeof:", typeof zlib.Inflate);
console.log("zlib.InflateRaw typeof:", typeof zlib.InflateRaw);
console.log("zlib.Unzip typeof:", typeof zlib.Unzip);
console.log("zlib.BrotliCompress typeof:", typeof zlib.BrotliCompress);
console.log("zlib.BrotliDecompress typeof:", typeof zlib.BrotliDecompress);
try {
  console.log("zlib.ZstdCompress typeof:", typeof zlib.ZstdCompress);
  console.log("zlib.ZstdDecompress typeof:", typeof zlib.ZstdDecompress);
} catch (e) {
  console.log("zstd classes area error:", (e as Error).message);
}

// ── Factory Functions ──
try {
  console.log("createDeflate typeof:", typeof zlib.createDeflate);
  console.log("createDeflateRaw typeof:", typeof zlib.createDeflateRaw);
  console.log("createGunzip typeof:", typeof zlib.createGunzip);
  console.log("createGzip typeof:", typeof zlib.createGzip);
  console.log("createInflate typeof:", typeof zlib.createInflate);
  console.log("createInflateRaw typeof:", typeof zlib.createInflateRaw);
  console.log("createUnzip typeof:", typeof zlib.createUnzip);
  console.log("createBrotliCompress typeof:", typeof zlib.createBrotliCompress);
  console.log("createBrotliDecompress typeof:", typeof zlib.createBrotliDecompress);
} catch (e) {
  console.log("factory typeof area error:", (e as Error).message);
}
try {
  console.log("createZstdCompress typeof:", typeof zlib.createZstdCompress);
  console.log("createZstdDecompress typeof:", typeof zlib.createZstdDecompress);
} catch (e) {
  console.log("zstd factory area error:", (e as Error).message);
}

// ── Convenience Functions (callback + sync) ──
// Sync round-trips through a fixed Buffer.
try {
  const fixed = Buffer.from("hello world");
  console.log("gzip roundtrip:", zlib.gunzipSync(zlib.gzipSync(fixed)).toString());
  console.log("deflate roundtrip:", zlib.inflateSync(zlib.deflateSync(fixed)).toString());
  console.log("deflateRaw roundtrip:", zlib.inflateRawSync(zlib.deflateRawSync(fixed)).toString());
  console.log("brotli roundtrip:", zlib.brotliDecompressSync(zlib.brotliCompressSync(fixed)).toString());
  // unzip auto-detects gzip vs deflate header
  console.log("unzipSync gzip:", zlib.unzipSync(zlib.gzipSync(fixed)).toString());
} catch (e) {
  console.log("sync codec area error:", (e as Error).message);
}
// Typeof callback-form fns (don't invoke — non-deterministic ordering with sync output)
try {
  console.log("deflate typeof:", typeof zlib.deflate);
  console.log("deflateRaw typeof:", typeof zlib.deflateRaw);
  console.log("gzip typeof:", typeof zlib.gzip);
  console.log("gunzip typeof:", typeof zlib.gunzip);
  console.log("inflate typeof:", typeof zlib.inflate);
  console.log("inflateRaw typeof:", typeof zlib.inflateRaw);
  console.log("unzip typeof:", typeof zlib.unzip);
  console.log("brotliCompress typeof:", typeof zlib.brotliCompress);
  console.log("brotliDecompress typeof:", typeof zlib.brotliDecompress);
} catch (e) {
  console.log("callback typeof area error:", (e as Error).message);
}
// Async forms via util.promisify
try {
  const util = await import("node:util");
  const gzipP = util.promisify(zlib.gzip);
  const gunzipP = util.promisify(zlib.gunzip);
  const compressed = await gzipP(Buffer.from("hello world"));
  console.log("promisify gzip ok:", compressed.length > 0);
  const decompressed = await gunzipP(compressed);
  console.log("promisify gunzip:", decompressed.toString());
} catch (e) {
  console.log("promisify area error:", (e as Error).message);
}
// Zstd (Node 22+): try/catch — may not be implemented
try {
  const fixed = Buffer.from("hello world");
  const z = zlib.zstdCompressSync(fixed);
  console.log("zstd roundtrip:", zlib.zstdDecompressSync(z).toString());
} catch (e) {
  console.log("zstd sync area error:", (e as Error).message);
}
try {
  console.log("zstdCompress typeof:", typeof zlib.zstdCompress);
  console.log("zstdDecompress typeof:", typeof zlib.zstdDecompress);
} catch (e) {
  console.log("zstd callback typeof area error:", (e as Error).message);
}

// ── ZlibBase Methods / Properties ──
// These are instance methods on a stream — probe via typeof on a created instance.
try {
  const g = zlib.createGzip();
  console.log("instance close typeof:", typeof g.close);
  console.log("instance flush typeof:", typeof g.flush);
  console.log("instance params typeof:", typeof g.params);
  console.log("instance reset typeof:", typeof g.reset);
  console.log("instance bytesWritten typeof:", typeof g.bytesWritten);
  console.log("instance bytesRead typeof:", typeof g.bytesRead);
  g.destroy();
} catch (e) {
  console.log("zlibbase area error:", (e as Error).message);
}

// ── Streaming codec: pipe a fixed Buffer through createGzip ──
try {
  const gz = zlib.createGzip();
  const chunks: Buffer[] = [];
  await new Promise<void>((resolve, reject) => {
    gz.on("data", (c: Buffer) => chunks.push(c));
    gz.on("end", () => resolve());
    gz.on("error", (err: Error) => reject(err));
    gz.end(Buffer.from("hello world"));
  });
  const compressed = Buffer.concat(chunks);
  console.log("createGzip stream out len>0:", compressed.length > 0);
  // Decompress to verify roundtrip
  console.log("createGzip stream roundtrip:", zlib.gunzipSync(compressed).toString());
} catch (e) {
  console.log("createGzip stream area error:", (e as Error).message);
}
try {
  const br = zlib.createBrotliCompress();
  const decoder = zlib.createBrotliDecompress();
  const chunks: Buffer[] = [];
  await new Promise<void>((resolve, reject) => {
    br.pipe(decoder);
    decoder.on("data", (c: Buffer) => chunks.push(c));
    decoder.on("end", () => resolve());
    decoder.on("error", (err: Error) => reject(err));
    br.end(Buffer.from("hello world"));
  });
  console.log("createBrotli pipe roundtrip:", Buffer.concat(chunks).toString());
} catch (e) {
  console.log("createBrotli stream area error:", (e as Error).message);
}

// ── Other Functions ──
try {
  console.log("crc32 hello:", zlib.crc32(Buffer.from("hello")));
  console.log("crc32 empty seed:", zlib.crc32(Buffer.from(""), 0));
} catch (e) {
  console.log("crc32 area error:", (e as Error).message);
}
console.log("zlib.constants typeof:", typeof zlib.constants);

// ── Constants — Flush Values ──
try {
  console.log("Z_NO_FLUSH:", zlib.constants.Z_NO_FLUSH);
  console.log("Z_PARTIAL_FLUSH:", zlib.constants.Z_PARTIAL_FLUSH);
  console.log("Z_SYNC_FLUSH:", zlib.constants.Z_SYNC_FLUSH);
  console.log("Z_FULL_FLUSH:", zlib.constants.Z_FULL_FLUSH);
  console.log("Z_FINISH:", zlib.constants.Z_FINISH);
  console.log("Z_BLOCK:", zlib.constants.Z_BLOCK);
  console.log("Z_TREES:", zlib.constants.Z_TREES);
} catch (e) {
  console.log("flush const area error:", (e as Error).message);
}

// ── Constants — Return Codes ──
try {
  console.log("Z_OK:", zlib.constants.Z_OK);
  console.log("Z_STREAM_END:", zlib.constants.Z_STREAM_END);
  console.log("Z_NEED_DICT:", zlib.constants.Z_NEED_DICT);
  console.log("Z_ERRNO:", zlib.constants.Z_ERRNO);
  console.log("Z_STREAM_ERROR:", zlib.constants.Z_STREAM_ERROR);
  console.log("Z_DATA_ERROR:", zlib.constants.Z_DATA_ERROR);
  console.log("Z_MEM_ERROR:", zlib.constants.Z_MEM_ERROR);
  console.log("Z_BUF_ERROR:", zlib.constants.Z_BUF_ERROR);
  console.log("Z_VERSION_ERROR:", zlib.constants.Z_VERSION_ERROR);
} catch (e) {
  console.log("retcode const area error:", (e as Error).message);
}

// ── Constants — Compression Levels ──
try {
  console.log("Z_NO_COMPRESSION:", zlib.constants.Z_NO_COMPRESSION);
  console.log("Z_BEST_SPEED:", zlib.constants.Z_BEST_SPEED);
  console.log("Z_BEST_COMPRESSION:", zlib.constants.Z_BEST_COMPRESSION);
  console.log("Z_DEFAULT_COMPRESSION:", zlib.constants.Z_DEFAULT_COMPRESSION);
} catch (e) {
  console.log("level const area error:", (e as Error).message);
}

// ── Constants — Strategy ──
try {
  console.log("Z_FILTERED:", zlib.constants.Z_FILTERED);
  console.log("Z_HUFFMAN_ONLY:", zlib.constants.Z_HUFFMAN_ONLY);
  console.log("Z_RLE:", zlib.constants.Z_RLE);
  console.log("Z_FIXED:", zlib.constants.Z_FIXED);
  console.log("Z_DEFAULT_STRATEGY:", zlib.constants.Z_DEFAULT_STRATEGY);
  console.log("ZLIB_VERNUM typeof:", typeof zlib.constants.ZLIB_VERNUM);
} catch (e) {
  console.log("strategy const area error:", (e as Error).message);
}

// ── Constants — Brotli ──
try {
  console.log("BROTLI_OPERATION_PROCESS:", zlib.constants.BROTLI_OPERATION_PROCESS);
  console.log("BROTLI_OPERATION_FLUSH:", zlib.constants.BROTLI_OPERATION_FLUSH);
  console.log("BROTLI_OPERATION_FINISH:", zlib.constants.BROTLI_OPERATION_FINISH);
  console.log("BROTLI_OPERATION_EMIT_METADATA:", zlib.constants.BROTLI_OPERATION_EMIT_METADATA);
  console.log("BROTLI_PARAM_MODE:", zlib.constants.BROTLI_PARAM_MODE);
  console.log("BROTLI_PARAM_QUALITY:", zlib.constants.BROTLI_PARAM_QUALITY);
  console.log("BROTLI_PARAM_SIZE_HINT:", zlib.constants.BROTLI_PARAM_SIZE_HINT);
  console.log("BROTLI_PARAM_LGWIN:", zlib.constants.BROTLI_PARAM_LGWIN);
  console.log("BROTLI_PARAM_LGBLOCK:", zlib.constants.BROTLI_PARAM_LGBLOCK);
  console.log("BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING:", zlib.constants.BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING);
  console.log("BROTLI_PARAM_LARGE_WINDOW:", zlib.constants.BROTLI_PARAM_LARGE_WINDOW);
  console.log("BROTLI_PARAM_NPOSTFIX:", zlib.constants.BROTLI_PARAM_NPOSTFIX);
  console.log("BROTLI_PARAM_NDIRECT:", zlib.constants.BROTLI_PARAM_NDIRECT);
} catch (e) {
  console.log("brotli const area error:", (e as Error).message);
}

// Coverage: 15 auto-emitted, 76 TODO, 0 skip-listed.

/*
@covers
crates/perry-stdlib/src/zlib.rs:
  - js_zlib_deflate_sync
  - js_zlib_gunzip
  - js_zlib_gunzip_sync
  - js_zlib_gzip
  - js_zlib_gzip_sync
  - js_zlib_inflate_sync
*/
