From facc2729859c6dbac15bb8df7d653797476758eb Mon Sep 17 00:00:00 2001 From: JordanMartinez Date: Mon, 27 Sep 2021 16:56:22 -0700 Subject: [PATCH] Finish PR 17 - Fix Gzip example (#36) * fix example Update node dependencies and fix example. * Update changelog * Drop eslint 'global Buffer' usage * Remove extra whitespace * Drop package-lock.json Co-authored-by: Matthew Leon --- .eslintrc.json | 1 + CHANGELOG.md | 1 + README.md | 2 ++ example/Gzip.js | 8 ++------ example/Gzip.purs | 14 ++++++++------ example/Gzip.txt | 1 + package.json | 2 ++ src/Node/Stream.js | 1 - 8 files changed, 17 insertions(+), 13 deletions(-) create mode 100644 example/Gzip.txt diff --git a/.eslintrc.json b/.eslintrc.json index 84cef4f..9f28578 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -4,6 +4,7 @@ }, "extends": "eslint:recommended", "env": { + "node": true, "commonjs": true }, "rules": { diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b58f79..fa592c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ New features: Bugfixes: Other improvements: +- Fix `Gzip` example (#17, #36 by @matthewleon and @JordanMartinez) ## [v5.0.0](https://github.com/purescript-node/purescript-posix-types/releases/tag/v5.0.0) - 2021-02-26 diff --git a/README.md b/README.md index 8b278ae..39b3dc4 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ A wrapper for Node's [Stream API](https://nodejs.org/api/stream.html). +See the `example` directory for a usage example. + ## Installation ``` diff --git a/example/Gzip.js b/example/Gzip.js index 150d693..2594c99 100644 --- a/example/Gzip.js +++ b/example/Gzip.js @@ -1,9 +1,5 @@ -/* global exports */ -/* global require */ "use strict"; -// module Gzip - -exports.gzip = require('zlib').createGzip; +exports.gzip = require("zlib").createGzip; +exports.fileStream = require("fs").createReadStream("example/Gzip.txt"); exports.stdout = process.stdout; -exports.stdin = process.stdin; diff --git a/example/Gzip.purs b/example/Gzip.purs index e4e52f6..abe2bad 100644 --- a/example/Gzip.purs +++ b/example/Gzip.purs @@ -3,15 +3,17 @@ module Gzip where import Prelude import Effect (Effect) -import Node.Stream (Duplex, Readable, Writable, pipe) - +import Effect.Console (log) +import Node.Stream (Duplex, Readable, Writable, onEnd, pipe) foreign import gzip :: Effect Duplex -foreign import stdin :: Readable () +foreign import fileStream :: Readable () foreign import stdout :: Writable () -main :: Effect (Writable ()) +main :: Effect Unit main = do z <- gzip - _ <- stdin `pipe` z - z `pipe` stdout + _ <- fileStream `pipe` z + _ <- z `pipe` stdout + void $ onEnd fileStream do + log "Done reading file, gzip output below" diff --git a/example/Gzip.txt b/example/Gzip.txt new file mode 100644 index 0000000..51d735e --- /dev/null +++ b/example/Gzip.txt @@ -0,0 +1 @@ +Compress me pretty please! diff --git a/package.json b/package.json index 191c3f0..901476d 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,8 @@ "scripts": { "clean": "rimraf output && rimraf .pulp-cache", "build": "eslint src && pulp build -- --censor-lib --strict", + "example:build": "eslint example && pulp build -I example -- --censor-lib --strict", + "example": "eslint example && pulp run -I example -m Gzip", "test": "pulp test -- --censor-lib --strict" }, "devDependencies": { diff --git a/src/Node/Stream.js b/src/Node/Stream.js index 0ca449b..d4fb2b1 100644 --- a/src/Node/Stream.js +++ b/src/Node/Stream.js @@ -1,4 +1,3 @@ -/* global Buffer */ "use strict"; exports.undefined = undefined;