Last active
June 7, 2026 08:05
-
-
Save pongo/64af2307036ff080afb3deb95b1f3bc2 to your computer and use it in GitHub Desktop.
zstd in node:zlib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { createReadStream, createWriteStream } from 'node:fs'; | |
| import zlib from 'node:zlib'; | |
| import { pipeline } from 'node:stream/promises'; | |
| async function backupFile(filePath) { | |
| const backupPath = `${filePath}.zst`; | |
| const source = createReadStream(filePath); | |
| const compressStream = zlib.createZstdCompress({ params: { [zlib.constants.ZSTD_c_compressionLevel]: 3 } }); | |
| const destination = createWriteStream(backupPath); | |
| await pipeline(source, compressStream, destination); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { readFileSync, writeFileSync } from 'node:fs'; | |
| import zlib from 'node:zlib'; | |
| function backupFileSync(filePath) { | |
| const data = readFileSync(filePath); | |
| const compressed = zlib.zstdCompressSync(data, { params: { [zlib.constants.ZSTD_c_compressionLevel]: 3 } }); | |
| const backupPath = `${filePath}.zst`; | |
| writeFileSync(backupPath, compressed); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment