Skip to content

Commit

Permalink
docs: finalize exports and add example of simple implode into readme
Browse files Browse the repository at this point in the history
  • Loading branch information
meszaros-lajos-gyorgy committed Jan 4, 2025
1 parent 132e254 commit 2bd3986
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,25 @@ fs.createReadStream(`path-to-compressed-file`)
.pipe(fs.createWriteStream(`path-to-write-decompressed-data`))
```

#### Non-stream compression (also works in browser)

```js
import fs from 'node:fs/promises'
import { implode } from 'node-pkware/simple'

const inputString = 'hello pkware!'

// create an ArrayBuffer from inputString
const encoder = new TextEncoder()
const input = encoder.encode(inputString).buffer

// compress it and get the result in another ArrayBuffer
const output = implode(input, 'ascii', 'large')

// write the output to a file
await fs.writeFile('/tmp/compressedHello', new Uint8Array(output))
```

### Catching errors

```js
Expand Down
5 changes: 3 additions & 2 deletions src/simple/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export function implode(
export { explode as decompress }
export { implode as compress }

// ---------------
// utils
// -----------------
// utils and types

export { concatArrayBuffers, sliceArrayBufferAt } from '@src/functions.js'
export { type CompressionType, type DictionarySize } from '@src/simple/types.js'

0 comments on commit 2bd3986

Please sign in to comment.