From e3de9fd281958e70d1801c2c3681634933b8e932 Mon Sep 17 00:00:00 2001 From: Sascha Schulz <sschulz@dh-software.de> Date: Mo, 16 Sep 2024 15:40:59 +0200 Subject: [PATCH] add examples for crypto and zlib --- templates/010-nodejs/zlib.js | 24 ++++++++++++++++++++++++ templates/010-nodejs/crypto.js | 3 +++ templates/010-nodejs/text-examples.txt | 2 ++ 3 files changed, 29 insertions(+), 0 deletions(-) diff --git a/templates/010-nodejs/crypto.js b/templates/010-nodejs/crypto.js new file mode 100644 index 0000000..019d5cb --- /dev/null +++ b/templates/010-nodejs/crypto.js @@ -0,0 +1,3 @@ +const crypto = require("crypto"); + +const hash = cryptop.createHash(/* algorythm */); // "md5", "sha256" diff --git a/templates/010-nodejs/text-examples.txt b/templates/010-nodejs/text-examples.txt new file mode 100644 index 0000000..89add94 --- /dev/null +++ b/templates/010-nodejs/text-examples.txt @@ -0,0 +1,2 @@ +TEXTCOLLBYfGiJUETHQ4hAcKSMd5zYpgqf1YRDhkmxHkhPWptrkoyz28wnI9V0aHeAuaKnak +TEXTCOLLBYfGiJUETHQ4hEcKSMd5zYpgqf1YRDhkmxHkhPWptrkoyz28wnI9V0aHeAuaKnak diff --git a/templates/010-nodejs/zlib.js b/templates/010-nodejs/zlib.js new file mode 100644 index 0000000..3508fc5 --- /dev/null +++ b/templates/010-nodejs/zlib.js @@ -0,0 +1,24 @@ +const zlib = require("zlib"); +const { pipeline } = require("stream"); + +// Komprimieren +zlib.deflate("abc" /* buffer | string */, (err, compressed) => { + +}); + +// Dekomprimieren +zlib.inflate(compressed /* buffer */, (err, decompressed) => { + +}); + +// Als Stream +const zipper = zlib.createDeflate(); +const unzipper = zlib.createInflate(); + +source.pipe(zipper).pipe(target); +source.pipe(unzipper).pipe(target); + +// einfachere Alternative +pipeline(source, zipper, target, (err) => { + console.error(err); +}); -- Gitblit v1.9.3