Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Commit 8d1bd12

Browse files
authored
Merge pull request #89 from exoego/zlib
Overhaul zlib module
2 parents 5e007a8 + ce6d7f7 commit 8d1bd12

17 files changed

+305
-193
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ The following core Node.js modules (v8.7.0+) have been implemented:
4747
| [url](https://nodejs.org/api/url.html) | :heavy_check_mark: |
4848
| [util](https://nodejs.org/api/util.html) | :heavy_check_mark: |
4949
| [vm](https://nodejs.org/api/vm.html) | :heavy_check_mark: |
50-
| [zlib](https://nodejs.org/api/zlib.html) | |
50+
| [zlib](https://nodejs.org/api/zlib.html) | :heavy_check_mark: |
5151

5252
## How to use
5353

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package io.scalajs.nodejs.zlib
2+
3+
import scala.scalajs.js
4+
import scala.scalajs.js.annotation.JSImport
5+
6+
/**
7+
* Available in Node.js v12 and later
8+
*/
9+
@js.native
10+
@JSImport("zlib", "BrotliCompress")
11+
class BrotliCompress extends ZlibBase
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package io.scalajs.nodejs.zlib
2+
3+
import scala.scalajs.js
4+
import scala.scalajs.js.annotation.JSImport
5+
6+
/**
7+
* Available in Node.js v12 and later
8+
*/
9+
@js.native
10+
@JSImport("zlib", "BrotliDecompress")
11+
class BrotliDecompress extends ZlibBase
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package io.scalajs.nodejs.zlib
2+
3+
import scala.scalajs.js
4+
5+
class BrotliOptions(
6+
var flush: js.UndefOr[Int] = js.undefined,
7+
var finishFlush: js.UndefOr[Int] = js.undefined,
8+
var chunkSize: js.UndefOr[Int] = js.undefined,
9+
var params: js.UndefOr[js.Dictionary[js.Any]] = js.undefined
10+
) extends js.Object

app/current/src/main/scala/io/scalajs/nodejs/zlib/CompressionAlgorithm.scala

Lines changed: 0 additions & 11 deletions
This file was deleted.

app/current/src/main/scala/io/scalajs/nodejs/zlib/CompressionOptions.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.scalajs.nodejs.zlib
22

33
import scala.scalajs.js
4+
import scala.scalajs.js.typedarray.{ArrayBuffer, DataView, TypedArray}
5+
import scala.scalajs.js.|
46

57
/**
68
* Compression Options
@@ -13,12 +15,13 @@ import scala.scalajs.js
1315
* @param strategy (compression only)
1416
* @param windowBits ???
1517
*/
16-
class CompressionOptions(var chunkSize: js.UndefOr[Int] = js.undefined,
17-
var dictionary: js.UndefOr[js.Dictionary[js.Any]] = js.undefined,
18-
var flush: js.UndefOr[CompressionFlush] = js.undefined,
18+
class CompressionOptions(var flush: js.UndefOr[CompressionFlush] = js.undefined,
1919
var finishFlush: js.UndefOr[CompressionFlush] = js.undefined,
20+
var chunkSize: js.UndefOr[Int] = js.undefined,
21+
var windowBits: js.UndefOr[Int] = js.undefined,
2022
var level: js.UndefOr[CompressionLevel] = js.undefined,
2123
var memLevel: js.UndefOr[CompressionLevel] = js.undefined,
2224
var strategy: js.UndefOr[CompressionStrategy] = js.undefined,
23-
var windowBits: js.UndefOr[Int] = js.undefined)
25+
var dictionary: js.UndefOr[TypedArray[_, _] | DataView | ArrayBuffer] = js.undefined,
26+
var info: js.UndefOr[Boolean] = js.undefined)
2427
extends js.Object
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
package io.scalajs.nodejs.zlib
2+
3+
import com.thoughtworks.enableMembersIf
4+
5+
import scala.scalajs.js
6+
import scala.scalajs.js.annotation.JSImport
7+
8+
@js.native
9+
@JSImport("zlib", "constants")
10+
object Constants extends UncategorizedConstants with BlotriConstants with ZlibConstants {}
11+
12+
@js.native
13+
trait UncategorizedConstants extends js.Object {
14+
val DEFLATE: Int = js.native
15+
val DEFLATERAW: Int = js.native
16+
val GUNZIP: Int = js.native
17+
val GZIP: Int = js.native
18+
val INFLATE: Int = js.native
19+
val INFLATERAW: Int = js.native
20+
val UNZIP: Int = js.native
21+
val ZLIB_VERNUM: Int = js.native
22+
}
23+
24+
@js.native
25+
trait ZlibConstants extends js.Object {
26+
val Z_DEFAULT_CHUNK: Int = js.native
27+
val Z_DEFAULT_LEVEL: Int = js.native
28+
val Z_DEFAULT_MEMLEVEL: Int = js.native
29+
val Z_DEFAULT_WINDOWBITS: Int = js.native
30+
val Z_MAX_CHUNK: Double = js.native
31+
val Z_MAX_LEVEL: Int = js.native
32+
val Z_MAX_MEMLEVEL: Int = js.native
33+
val Z_MAX_WINDOWBITS: Int = js.native
34+
val Z_MIN_CHUNK: Int = js.native
35+
val Z_MIN_LEVEL: Int = js.native
36+
val Z_MIN_MEMLEVEL: Int = js.native
37+
val Z_MIN_WINDOWBITS: Int = js.native
38+
39+
// Allowed flush values
40+
val Z_NO_FLUSH: CompressionFlush = js.native
41+
val Z_PARTIAL_FLUSH: CompressionFlush = js.native
42+
val Z_SYNC_FLUSH: CompressionFlush = js.native
43+
val Z_FULL_FLUSH: CompressionFlush = js.native
44+
val Z_FINISH: CompressionFlush = js.native
45+
val Z_BLOCK: CompressionFlush = js.native
46+
val Z_TREES: CompressionFlush = js.native
47+
48+
// Return codes for the compression/decompression functions.
49+
val Z_OK: CompressionFunction = js.native
50+
val Z_STREAM_END: CompressionFunction = js.native
51+
val Z_NEED_DICT: CompressionFunction = js.native
52+
val Z_ERRNO: CompressionFunction = js.native
53+
val Z_STREAM_ERROR: CompressionFunction = js.native
54+
val Z_DATA_ERROR: CompressionFunction = js.native
55+
val Z_MEM_ERROR: CompressionFunction = js.native
56+
val Z_BUF_ERROR: CompressionFunction = js.native
57+
val Z_VERSION_ERROR: CompressionFunction = js.native
58+
59+
// Compression levels
60+
val Z_NO_COMPRESSION: CompressionLevel = js.native
61+
val Z_BEST_SPEED: CompressionLevel = js.native
62+
val Z_BEST_COMPRESSION: CompressionLevel = js.native
63+
val Z_DEFAULT_COMPRESSION: CompressionLevel = js.native
64+
65+
// Compression strategies
66+
val Z_FILTERED: CompressionStrategy = js.native
67+
val Z_HUFFMAN_ONLY: CompressionStrategy = js.native
68+
val Z_RLE: CompressionStrategy = js.native
69+
val Z_FIXED: CompressionStrategy = js.native
70+
val Z_DEFAULT_STRATEGY: CompressionStrategy = js.native
71+
72+
// Possible values of the data_type field
73+
val Z_BINARY: DataType = js.native
74+
val Z_TEXT: DataType = js.native
75+
val Z_ASCII: DataType = js.native
76+
val Z_UNKNOWN: DataType = js.native
77+
78+
// The deflate compression method (the only one supported in this version).
79+
val Z_DEFLATED: DeflateCompressMethod = js.native
80+
81+
// For initializing zalloc, zfree, opaque.
82+
val Z_NULL: AllocationType = js.native
83+
}
84+
85+
@enableMembersIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs12)
86+
@js.native
87+
trait BlotriConstants extends js.Object {
88+
val BROTLI_DECODE: Int = js.native
89+
val BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES: Int = js.native
90+
val BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP: Int = js.native
91+
val BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES: Int = js.native
92+
val BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1: Int = js.native
93+
val BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2: Int = js.native
94+
val BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS: Int = js.native
95+
val BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET: Int = js.native
96+
val BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1: Int = js.native
97+
val BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2: Int = js.native
98+
val BROTLI_DECODER_ERROR_FORMAT_CL_SPACE: Int = js.native
99+
val BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT: Int = js.native
100+
val BROTLI_DECODER_ERROR_FORMAT_DICTIONARY: Int = js.native
101+
val BROTLI_DECODER_ERROR_FORMAT_DISTANCE: Int = js.native
102+
val BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE: Int = js.native
103+
val BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE: Int = js.native
104+
val BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE: Int = js.native
105+
val BROTLI_DECODER_ERROR_FORMAT_PADDING_1: Int = js.native
106+
val BROTLI_DECODER_ERROR_FORMAT_PADDING_2: Int = js.native
107+
val BROTLI_DECODER_ERROR_FORMAT_RESERVED: Int = js.native
108+
val BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET: Int = js.native
109+
val BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME: Int = js.native
110+
val BROTLI_DECODER_ERROR_FORMAT_TRANSFORM: Int = js.native
111+
val BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS: Int = js.native
112+
val BROTLI_DECODER_ERROR_INVALID_ARGUMENTS: Int = js.native
113+
val BROTLI_DECODER_ERROR_UNREACHABLE: Int = js.native
114+
val BROTLI_DECODER_NEEDS_MORE_INPUT: Int = js.native
115+
val BROTLI_DECODER_NEEDS_MORE_OUTPUT: Int = js.native
116+
val BROTLI_DECODER_NO_ERROR: Int = js.native
117+
val BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION: Int = js.native
118+
val BROTLI_DECODER_PARAM_LARGE_WINDOW: Int = js.native
119+
val BROTLI_DECODER_RESULT_ERROR: Int = js.native
120+
val BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT: Int = js.native
121+
val BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT: Int = js.native
122+
val BROTLI_DECODER_RESULT_SUCCESS: Int = js.native
123+
val BROTLI_DECODER_SUCCESS: Int = js.native
124+
val BROTLI_DEFAULT_MODE: Int = js.native
125+
val BROTLI_DEFAULT_QUALITY: Int = js.native
126+
val BROTLI_DEFAULT_WINDOW: Int = js.native
127+
val BROTLI_ENCODE: Int = js.native
128+
val BROTLI_LARGE_MAX_WINDOW_BITS: Int = js.native
129+
val BROTLI_MAX_INPUT_BLOCK_BITS: Int = js.native
130+
val BROTLI_MAX_QUALITY: Int = js.native
131+
val BROTLI_MAX_WINDOW_BITS: Int = js.native
132+
val BROTLI_MIN_INPUT_BLOCK_BITS: Int = js.native
133+
val BROTLI_MIN_QUALITY: Int = js.native
134+
val BROTLI_MIN_WINDOW_BITS: Int = js.native
135+
val BROTLI_MODE_FONT: Int = js.native
136+
val BROTLI_MODE_GENERIC: Int = js.native
137+
val BROTLI_MODE_TEXT: Int = js.native
138+
val BROTLI_OPERATION_EMIT_METADATA: Int = js.native
139+
val BROTLI_OPERATION_FINISH: Int = js.native
140+
val BROTLI_OPERATION_FLUSH: Int = js.native
141+
val BROTLI_OPERATION_PROCESS: Int = js.native
142+
val BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING: Int = js.native
143+
val BROTLI_PARAM_LARGE_WINDOW: Int = js.native
144+
val BROTLI_PARAM_LGBLOCK: Int = js.native
145+
val BROTLI_PARAM_LGWIN: Int = js.native
146+
val BROTLI_PARAM_MODE: Int = js.native
147+
val BROTLI_PARAM_NDIRECT: Int = js.native
148+
val BROTLI_PARAM_NPOSTFIX: Int = js.native
149+
val BROTLI_PARAM_QUALITY: Int = js.native
150+
val BROTLI_PARAM_SIZE_HINT: Int = js.native
151+
}

app/current/src/main/scala/io/scalajs/nodejs/zlib/Deflate.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package io.scalajs.nodejs
22
package zlib
33

44
import scala.scalajs.js
5+
import scala.scalajs.js.annotation.JSImport
56

67
/**
78
* Compress data using deflate.
89
*/
910
@js.native
10-
trait Deflate extends CompressionAlgorithm
11+
@JSImport("zlib", "Deflate")
12+
class Deflate extends ZlibBase

app/current/src/main/scala/io/scalajs/nodejs/zlib/DeflateRaw.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package io.scalajs.nodejs
22
package zlib
33

44
import scala.scalajs.js
5+
import scala.scalajs.js.annotation.JSImport
56

67
/**
78
* Compress data using deflate, and do not append a zlib header.
89
*/
910
@js.native
10-
trait DeflateRaw extends CompressionAlgorithm
11+
@JSImport("zlib", "DeflateRaw")
12+
class DeflateRaw extends ZlibBase

app/current/src/main/scala/io/scalajs/nodejs/zlib/Gunzip.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package io.scalajs.nodejs
22
package zlib
33

44
import scala.scalajs.js
5+
import scala.scalajs.js.annotation.JSImport
56

67
/**
78
* Decompress a gzip stream.
89
*/
910
@js.native
10-
trait Gunzip extends CompressionAlgorithm
11+
@JSImport("zlib", "Gunzip")
12+
class Gunzip extends ZlibBase

app/current/src/main/scala/io/scalajs/nodejs/zlib/Gzip.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package io.scalajs.nodejs
22
package zlib
33

44
import scala.scalajs.js
5+
import scala.scalajs.js.annotation.JSImport
56

67
/**
78
* Compress data using gzip.
89
*/
910
@js.native
10-
trait Gzip extends CompressionAlgorithm
11+
@JSImport("zlib", "Gzip")
12+
class Gzip extends ZlibBase

app/current/src/main/scala/io/scalajs/nodejs/zlib/Inflate.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package io.scalajs.nodejs
22
package zlib
33

44
import scala.scalajs.js
5+
import scala.scalajs.js.annotation.JSImport
56

67
/**
78
* Decompress a deflate stream.
89
*/
910
@js.native
10-
trait Inflate extends CompressionAlgorithm
11+
@JSImport("zlib", "Inflate")
12+
class Inflate extends ZlibBase

app/current/src/main/scala/io/scalajs/nodejs/zlib/InflateRaw.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package io.scalajs.nodejs
22
package zlib
33

44
import scala.scalajs.js
5+
import scala.scalajs.js.annotation.JSImport
56

67
/**
78
* Decompress a raw deflate stream.
89
*/
910
@js.native
10-
trait InflateRaw extends CompressionAlgorithm
11+
@JSImport("zlib", "InflateRaw")
12+
class InflateRaw extends ZlibBase

app/current/src/main/scala/io/scalajs/nodejs/zlib/Unzip.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package io.scalajs.nodejs
22
package zlib
33

44
import scala.scalajs.js
5+
import scala.scalajs.js.annotation.JSImport
56

67
/**
78
* Decompress a raw deflate stream.
89
*/
910
@js.native
10-
trait Unzip extends CompressionAlgorithm
11+
@JSImport("zlib", "Unzip")
12+
class Unzip extends ZlibBase

0 commit comments

Comments
 (0)