generated from napi-rs/package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement compress and uncompress
- Loading branch information
1 parent
adc3418
commit df2ccd2
Showing
36 changed files
with
881 additions
and
181 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
import { Duplex } from 'stream' | ||
|
||
import test from 'ava' | ||
|
||
import { SnappyStream } from '../index' | ||
import { compressSync, compress, uncompressSync, uncompress } from '../index' | ||
|
||
test('should be able to compress Buffer', (t) => { | ||
const fixture = 'hello world' | ||
t.deepEqual(compressSync(fixture), Buffer.from([11, 40, 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100])) | ||
}) | ||
|
||
test('compress should be async version of compressSync', async (t) => { | ||
const fixture = 'hello world 😂 🎧 🚀' | ||
t.deepEqual(await compress(fixture), compressSync(fixture)) | ||
}) | ||
|
||
test('should be able to decompress sync', (t) => { | ||
const fixture = 'hello world 😂 🎧 🚀' | ||
t.deepEqual(uncompressSync(compressSync(fixture)), Buffer.from(fixture)) | ||
}) | ||
|
||
test('SnappyStream should be instance of Duplex', (t) => { | ||
t.true(new SnappyStream() instanceof Duplex) | ||
test('should be able to decompress', async (t) => { | ||
const fixture = 'hello world 😂 🎧 🚀' | ||
t.deepEqual(await uncompress(await compress(fixture)), Buffer.from(fixture)) | ||
}) |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export function compressSync(input: Buffer | string | ArrayBuffer | Uint8Array): Buffer | ||
export function compress(input: Buffer | string | ArrayBuffer | Uint8Array): Promise<Buffer> | ||
export function uncompressSync(compressed: Buffer): Buffer | ||
export function uncompress(compressed: Buffer): Promise<Buffer> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const { loadBinding } = require('@node-rs/helper') | ||
|
||
const { | ||
compressSync: _compressSync, | ||
compress: _compress, | ||
uncompress, | ||
uncompressSync, | ||
} = loadBinding(__dirname, 'snappy', '@napi-rs/snappy') | ||
|
||
module.exports = { | ||
compressSync: function compressSync(input) { | ||
return _compressSync(Buffer.from(input)) | ||
}, | ||
compress: function compress(input) { | ||
return _compress(Buffer.from(input)) | ||
}, | ||
uncompress, | ||
uncompressSync, | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# `@napi-rs/package-template-android-arm64` | ||
# `@napi-rs/snappy-android-arm64` | ||
|
||
This is the **aarch64-linux-android** binary for `@napi-rs/package-template` | ||
This is the **aarch64-linux-android** binary for `@napi-rs/snappy` |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# `@napi-rs/package-template-darwin-arm64` | ||
# `@napi-rs/snappy-darwin-arm64` | ||
|
||
This is the **aarch64-apple-darwin** binary for `@napi-rs/package-template` | ||
This is the **aarch64-apple-darwin** binary for `@napi-rs/snappy` |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# `@napi-rs/package-template-darwin-x64` | ||
# `@napi-rs/snappy-darwin-x64` | ||
|
||
This is the **x86_64-apple-darwin** binary for `@napi-rs/package-template` | ||
This is the **x86_64-apple-darwin** binary for `@napi-rs/snappy` |
Oops, something went wrong.