diff --git a/README.md b/README.md index a06f232e0..e94e1f21d 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ The following core Node.js modules (v8.7.0+) have been implemented: | [url](https://nodejs.org/api/url.html) | :heavy_check_mark: | | [util](https://nodejs.org/api/util.html) | :heavy_check_mark: | | [vm](https://nodejs.org/api/vm.html) | :heavy_check_mark: | -| [zlib](https://nodejs.org/api/zlib.html) | | +| [zlib](https://nodejs.org/api/zlib.html) | :heavy_check_mark: | ## How to use diff --git a/app/current/src/main/scala/io/scalajs/nodejs/zlib/BrotliCompress.scala b/app/current/src/main/scala/io/scalajs/nodejs/zlib/BrotliCompress.scala new file mode 100644 index 000000000..f6289df1a --- /dev/null +++ b/app/current/src/main/scala/io/scalajs/nodejs/zlib/BrotliCompress.scala @@ -0,0 +1,11 @@ +package io.scalajs.nodejs.zlib + +import scala.scalajs.js +import scala.scalajs.js.annotation.JSImport + +/** + * Available in Node.js v12 and later + */ +@js.native +@JSImport("zlib", "BrotliCompress") +class BrotliCompress extends ZlibBase diff --git a/app/current/src/main/scala/io/scalajs/nodejs/zlib/BrotliDecompress.scala b/app/current/src/main/scala/io/scalajs/nodejs/zlib/BrotliDecompress.scala new file mode 100644 index 000000000..9787a7603 --- /dev/null +++ b/app/current/src/main/scala/io/scalajs/nodejs/zlib/BrotliDecompress.scala @@ -0,0 +1,11 @@ +package io.scalajs.nodejs.zlib + +import scala.scalajs.js +import scala.scalajs.js.annotation.JSImport + +/** + * Available in Node.js v12 and later + */ +@js.native +@JSImport("zlib", "BrotliDecompress") +class BrotliDecompress extends ZlibBase diff --git a/app/current/src/main/scala/io/scalajs/nodejs/zlib/BrotliOptions.scala b/app/current/src/main/scala/io/scalajs/nodejs/zlib/BrotliOptions.scala new file mode 100644 index 000000000..37b38fad0 --- /dev/null +++ b/app/current/src/main/scala/io/scalajs/nodejs/zlib/BrotliOptions.scala @@ -0,0 +1,10 @@ +package io.scalajs.nodejs.zlib + +import scala.scalajs.js + +class BrotliOptions( + var flush: js.UndefOr[Int] = js.undefined, + var finishFlush: js.UndefOr[Int] = js.undefined, + var chunkSize: js.UndefOr[Int] = js.undefined, + var params: js.UndefOr[js.Dictionary[js.Any]] = js.undefined +) extends js.Object diff --git a/app/current/src/main/scala/io/scalajs/nodejs/zlib/CompressionAlgorithm.scala b/app/current/src/main/scala/io/scalajs/nodejs/zlib/CompressionAlgorithm.scala deleted file mode 100644 index 81e71724e..000000000 --- a/app/current/src/main/scala/io/scalajs/nodejs/zlib/CompressionAlgorithm.scala +++ /dev/null @@ -1,11 +0,0 @@ -package io.scalajs.nodejs.zlib - -import io.scalajs.nodejs.stream - -import scala.scalajs.js - -/** - * Compression Algorithm - */ -@js.native -trait CompressionAlgorithm extends stream.Transform diff --git a/app/current/src/main/scala/io/scalajs/nodejs/zlib/CompressionOptions.scala b/app/current/src/main/scala/io/scalajs/nodejs/zlib/CompressionOptions.scala index bafe7e8ef..e9ce10ce7 100644 --- a/app/current/src/main/scala/io/scalajs/nodejs/zlib/CompressionOptions.scala +++ b/app/current/src/main/scala/io/scalajs/nodejs/zlib/CompressionOptions.scala @@ -1,6 +1,8 @@ package io.scalajs.nodejs.zlib import scala.scalajs.js +import scala.scalajs.js.typedarray.{ArrayBuffer, DataView, TypedArray} +import scala.scalajs.js.| /** * Compression Options @@ -13,12 +15,13 @@ import scala.scalajs.js * @param strategy (compression only) * @param windowBits ??? */ -class CompressionOptions(var chunkSize: js.UndefOr[Int] = js.undefined, - var dictionary: js.UndefOr[js.Dictionary[js.Any]] = js.undefined, - var flush: js.UndefOr[CompressionFlush] = js.undefined, +class CompressionOptions(var flush: js.UndefOr[CompressionFlush] = js.undefined, var finishFlush: js.UndefOr[CompressionFlush] = js.undefined, + var chunkSize: js.UndefOr[Int] = js.undefined, + var windowBits: js.UndefOr[Int] = js.undefined, var level: js.UndefOr[CompressionLevel] = js.undefined, var memLevel: js.UndefOr[CompressionLevel] = js.undefined, var strategy: js.UndefOr[CompressionStrategy] = js.undefined, - var windowBits: js.UndefOr[Int] = js.undefined) + var dictionary: js.UndefOr[TypedArray[_, _] | DataView | ArrayBuffer] = js.undefined, + var info: js.UndefOr[Boolean] = js.undefined) extends js.Object diff --git a/app/current/src/main/scala/io/scalajs/nodejs/zlib/Constants.scala b/app/current/src/main/scala/io/scalajs/nodejs/zlib/Constants.scala new file mode 100644 index 000000000..521caa3d0 --- /dev/null +++ b/app/current/src/main/scala/io/scalajs/nodejs/zlib/Constants.scala @@ -0,0 +1,151 @@ +package io.scalajs.nodejs.zlib + +import com.thoughtworks.enableMembersIf + +import scala.scalajs.js +import scala.scalajs.js.annotation.JSImport + +@js.native +@JSImport("zlib", "constants") +object Constants extends UncategorizedConstants with BlotriConstants with ZlibConstants {} + +@js.native +trait UncategorizedConstants extends js.Object { + val DEFLATE: Int = js.native + val DEFLATERAW: Int = js.native + val GUNZIP: Int = js.native + val GZIP: Int = js.native + val INFLATE: Int = js.native + val INFLATERAW: Int = js.native + val UNZIP: Int = js.native + val ZLIB_VERNUM: Int = js.native +} + +@js.native +trait ZlibConstants extends js.Object { + val Z_DEFAULT_CHUNK: Int = js.native + val Z_DEFAULT_LEVEL: Int = js.native + val Z_DEFAULT_MEMLEVEL: Int = js.native + val Z_DEFAULT_WINDOWBITS: Int = js.native + val Z_MAX_CHUNK: Double = js.native + val Z_MAX_LEVEL: Int = js.native + val Z_MAX_MEMLEVEL: Int = js.native + val Z_MAX_WINDOWBITS: Int = js.native + val Z_MIN_CHUNK: Int = js.native + val Z_MIN_LEVEL: Int = js.native + val Z_MIN_MEMLEVEL: Int = js.native + val Z_MIN_WINDOWBITS: Int = js.native + + // Allowed flush values + val Z_NO_FLUSH: CompressionFlush = js.native + val Z_PARTIAL_FLUSH: CompressionFlush = js.native + val Z_SYNC_FLUSH: CompressionFlush = js.native + val Z_FULL_FLUSH: CompressionFlush = js.native + val Z_FINISH: CompressionFlush = js.native + val Z_BLOCK: CompressionFlush = js.native + val Z_TREES: CompressionFlush = js.native + + // Return codes for the compression/decompression functions. + val Z_OK: CompressionFunction = js.native + val Z_STREAM_END: CompressionFunction = js.native + val Z_NEED_DICT: CompressionFunction = js.native + val Z_ERRNO: CompressionFunction = js.native + val Z_STREAM_ERROR: CompressionFunction = js.native + val Z_DATA_ERROR: CompressionFunction = js.native + val Z_MEM_ERROR: CompressionFunction = js.native + val Z_BUF_ERROR: CompressionFunction = js.native + val Z_VERSION_ERROR: CompressionFunction = js.native + + // Compression levels + val Z_NO_COMPRESSION: CompressionLevel = js.native + val Z_BEST_SPEED: CompressionLevel = js.native + val Z_BEST_COMPRESSION: CompressionLevel = js.native + val Z_DEFAULT_COMPRESSION: CompressionLevel = js.native + + // Compression strategies + val Z_FILTERED: CompressionStrategy = js.native + val Z_HUFFMAN_ONLY: CompressionStrategy = js.native + val Z_RLE: CompressionStrategy = js.native + val Z_FIXED: CompressionStrategy = js.native + val Z_DEFAULT_STRATEGY: CompressionStrategy = js.native + + // Possible values of the data_type field + val Z_BINARY: DataType = js.native + val Z_TEXT: DataType = js.native + val Z_ASCII: DataType = js.native + val Z_UNKNOWN: DataType = js.native + + // The deflate compression method (the only one supported in this version). + val Z_DEFLATED: DeflateCompressMethod = js.native + + // For initializing zalloc, zfree, opaque. + val Z_NULL: AllocationType = js.native +} + +@enableMembersIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs12) +@js.native +trait BlotriConstants extends js.Object { + val BROTLI_DECODE: Int = js.native + val BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES: Int = js.native + val BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP: Int = js.native + val BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES: Int = js.native + val BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1: Int = js.native + val BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2: Int = js.native + val BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS: Int = js.native + val BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET: Int = js.native + val BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1: Int = js.native + val BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2: Int = js.native + val BROTLI_DECODER_ERROR_FORMAT_CL_SPACE: Int = js.native + val BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT: Int = js.native + val BROTLI_DECODER_ERROR_FORMAT_DICTIONARY: Int = js.native + val BROTLI_DECODER_ERROR_FORMAT_DISTANCE: Int = js.native + val BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE: Int = js.native + val BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE: Int = js.native + val BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE: Int = js.native + val BROTLI_DECODER_ERROR_FORMAT_PADDING_1: Int = js.native + val BROTLI_DECODER_ERROR_FORMAT_PADDING_2: Int = js.native + val BROTLI_DECODER_ERROR_FORMAT_RESERVED: Int = js.native + val BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET: Int = js.native + val BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME: Int = js.native + val BROTLI_DECODER_ERROR_FORMAT_TRANSFORM: Int = js.native + val BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS: Int = js.native + val BROTLI_DECODER_ERROR_INVALID_ARGUMENTS: Int = js.native + val BROTLI_DECODER_ERROR_UNREACHABLE: Int = js.native + val BROTLI_DECODER_NEEDS_MORE_INPUT: Int = js.native + val BROTLI_DECODER_NEEDS_MORE_OUTPUT: Int = js.native + val BROTLI_DECODER_NO_ERROR: Int = js.native + val BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION: Int = js.native + val BROTLI_DECODER_PARAM_LARGE_WINDOW: Int = js.native + val BROTLI_DECODER_RESULT_ERROR: Int = js.native + val BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT: Int = js.native + val BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT: Int = js.native + val BROTLI_DECODER_RESULT_SUCCESS: Int = js.native + val BROTLI_DECODER_SUCCESS: Int = js.native + val BROTLI_DEFAULT_MODE: Int = js.native + val BROTLI_DEFAULT_QUALITY: Int = js.native + val BROTLI_DEFAULT_WINDOW: Int = js.native + val BROTLI_ENCODE: Int = js.native + val BROTLI_LARGE_MAX_WINDOW_BITS: Int = js.native + val BROTLI_MAX_INPUT_BLOCK_BITS: Int = js.native + val BROTLI_MAX_QUALITY: Int = js.native + val BROTLI_MAX_WINDOW_BITS: Int = js.native + val BROTLI_MIN_INPUT_BLOCK_BITS: Int = js.native + val BROTLI_MIN_QUALITY: Int = js.native + val BROTLI_MIN_WINDOW_BITS: Int = js.native + val BROTLI_MODE_FONT: Int = js.native + val BROTLI_MODE_GENERIC: Int = js.native + val BROTLI_MODE_TEXT: Int = js.native + val BROTLI_OPERATION_EMIT_METADATA: Int = js.native + val BROTLI_OPERATION_FINISH: Int = js.native + val BROTLI_OPERATION_FLUSH: Int = js.native + val BROTLI_OPERATION_PROCESS: Int = js.native + val BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING: Int = js.native + val BROTLI_PARAM_LARGE_WINDOW: Int = js.native + val BROTLI_PARAM_LGBLOCK: Int = js.native + val BROTLI_PARAM_LGWIN: Int = js.native + val BROTLI_PARAM_MODE: Int = js.native + val BROTLI_PARAM_NDIRECT: Int = js.native + val BROTLI_PARAM_NPOSTFIX: Int = js.native + val BROTLI_PARAM_QUALITY: Int = js.native + val BROTLI_PARAM_SIZE_HINT: Int = js.native +} diff --git a/app/current/src/main/scala/io/scalajs/nodejs/zlib/Deflate.scala b/app/current/src/main/scala/io/scalajs/nodejs/zlib/Deflate.scala index 7b6035d3f..42ee4e049 100644 --- a/app/current/src/main/scala/io/scalajs/nodejs/zlib/Deflate.scala +++ b/app/current/src/main/scala/io/scalajs/nodejs/zlib/Deflate.scala @@ -2,9 +2,11 @@ package io.scalajs.nodejs package zlib import scala.scalajs.js +import scala.scalajs.js.annotation.JSImport /** * Compress data using deflate. */ @js.native -trait Deflate extends CompressionAlgorithm +@JSImport("zlib", "Deflate") +class Deflate extends ZlibBase diff --git a/app/current/src/main/scala/io/scalajs/nodejs/zlib/DeflateRaw.scala b/app/current/src/main/scala/io/scalajs/nodejs/zlib/DeflateRaw.scala index 4e222f860..34adf334f 100644 --- a/app/current/src/main/scala/io/scalajs/nodejs/zlib/DeflateRaw.scala +++ b/app/current/src/main/scala/io/scalajs/nodejs/zlib/DeflateRaw.scala @@ -2,9 +2,11 @@ package io.scalajs.nodejs package zlib import scala.scalajs.js +import scala.scalajs.js.annotation.JSImport /** * Compress data using deflate, and do not append a zlib header. */ @js.native -trait DeflateRaw extends CompressionAlgorithm +@JSImport("zlib", "DeflateRaw") +class DeflateRaw extends ZlibBase diff --git a/app/current/src/main/scala/io/scalajs/nodejs/zlib/Gunzip.scala b/app/current/src/main/scala/io/scalajs/nodejs/zlib/Gunzip.scala index d3761a9af..257cf1c47 100644 --- a/app/current/src/main/scala/io/scalajs/nodejs/zlib/Gunzip.scala +++ b/app/current/src/main/scala/io/scalajs/nodejs/zlib/Gunzip.scala @@ -2,9 +2,11 @@ package io.scalajs.nodejs package zlib import scala.scalajs.js +import scala.scalajs.js.annotation.JSImport /** * Decompress a gzip stream. */ @js.native -trait Gunzip extends CompressionAlgorithm +@JSImport("zlib", "Gunzip") +class Gunzip extends ZlibBase diff --git a/app/current/src/main/scala/io/scalajs/nodejs/zlib/Gzip.scala b/app/current/src/main/scala/io/scalajs/nodejs/zlib/Gzip.scala index c7197d604..e6fbb2859 100644 --- a/app/current/src/main/scala/io/scalajs/nodejs/zlib/Gzip.scala +++ b/app/current/src/main/scala/io/scalajs/nodejs/zlib/Gzip.scala @@ -2,9 +2,11 @@ package io.scalajs.nodejs package zlib import scala.scalajs.js +import scala.scalajs.js.annotation.JSImport /** * Compress data using gzip. */ @js.native -trait Gzip extends CompressionAlgorithm +@JSImport("zlib", "Gzip") +class Gzip extends ZlibBase diff --git a/app/current/src/main/scala/io/scalajs/nodejs/zlib/Inflate.scala b/app/current/src/main/scala/io/scalajs/nodejs/zlib/Inflate.scala index 0c77a515a..61006f536 100644 --- a/app/current/src/main/scala/io/scalajs/nodejs/zlib/Inflate.scala +++ b/app/current/src/main/scala/io/scalajs/nodejs/zlib/Inflate.scala @@ -2,9 +2,11 @@ package io.scalajs.nodejs package zlib import scala.scalajs.js +import scala.scalajs.js.annotation.JSImport /** * Decompress a deflate stream. */ @js.native -trait Inflate extends CompressionAlgorithm +@JSImport("zlib", "Inflate") +class Inflate extends ZlibBase diff --git a/app/current/src/main/scala/io/scalajs/nodejs/zlib/InflateRaw.scala b/app/current/src/main/scala/io/scalajs/nodejs/zlib/InflateRaw.scala index 5291d1874..adfd6d4e7 100644 --- a/app/current/src/main/scala/io/scalajs/nodejs/zlib/InflateRaw.scala +++ b/app/current/src/main/scala/io/scalajs/nodejs/zlib/InflateRaw.scala @@ -2,9 +2,11 @@ package io.scalajs.nodejs package zlib import scala.scalajs.js +import scala.scalajs.js.annotation.JSImport /** * Decompress a raw deflate stream. */ @js.native -trait InflateRaw extends CompressionAlgorithm +@JSImport("zlib", "InflateRaw") +class InflateRaw extends ZlibBase diff --git a/app/current/src/main/scala/io/scalajs/nodejs/zlib/Unzip.scala b/app/current/src/main/scala/io/scalajs/nodejs/zlib/Unzip.scala index 4a0bb11c9..207bc5628 100644 --- a/app/current/src/main/scala/io/scalajs/nodejs/zlib/Unzip.scala +++ b/app/current/src/main/scala/io/scalajs/nodejs/zlib/Unzip.scala @@ -2,9 +2,11 @@ package io.scalajs.nodejs package zlib import scala.scalajs.js +import scala.scalajs.js.annotation.JSImport /** * Decompress a raw deflate stream. */ @js.native -trait Unzip extends CompressionAlgorithm +@JSImport("zlib", "Unzip") +class Unzip extends ZlibBase diff --git a/app/current/src/main/scala/io/scalajs/nodejs/zlib/Zlib.scala b/app/current/src/main/scala/io/scalajs/nodejs/zlib/Zlib.scala index d09f82ed7..e9cdfcb2c 100644 --- a/app/current/src/main/scala/io/scalajs/nodejs/zlib/Zlib.scala +++ b/app/current/src/main/scala/io/scalajs/nodejs/zlib/Zlib.scala @@ -1,11 +1,10 @@ package io.scalajs.nodejs.zlib -import io.scalajs.nodejs.buffer.Buffer +import com.thoughtworks.enableIf import io.scalajs.nodejs.events.IEventEmitter import scala.scalajs.js import scala.scalajs.js.annotation.JSImport -import scala.scalajs.js.| /** * This provides bindings to Gzip/Gunzip, Deflate/Inflate, and DeflateRaw/InflateRaw classes. @@ -13,60 +12,13 @@ import scala.scalajs.js.| * @see https://nodejs.org/docs/latest/api/zlib.html */ @js.native -trait Zlib extends IEventEmitter { +trait Zlib extends IEventEmitter with UncategorizedConstants with ZlibConstants { - ///////////////////////////////////////////////////////////////////////////////// - // Properties - ///////////////////////////////////////////////////////////////////////////////// - - // Allowed flush values - val Z_NO_FLUSH: CompressionFlush = js.native - val Z_PARTIAL_FLUSH: CompressionFlush = js.native - val Z_SYNC_FLUSH: CompressionFlush = js.native - val Z_FULL_FLUSH: CompressionFlush = js.native - val Z_FINISH: CompressionFlush = js.native - val Z_BLOCK: CompressionFlush = js.native - val Z_TREES: CompressionFlush = js.native - - // Return codes for the compression/decompression functions. - val Z_OK: CompressionFunction = js.native - val Z_STREAM_END: CompressionFunction = js.native - val Z_NEED_DICT: CompressionFunction = js.native - val Z_ERRNO: CompressionFunction = js.native - val Z_STREAM_ERROR: CompressionFunction = js.native - val Z_DATA_ERROR: CompressionFunction = js.native - val Z_MEM_ERROR: CompressionFunction = js.native - val Z_BUF_ERROR: CompressionFunction = js.native - val Z_VERSION_ERROR: CompressionFunction = js.native - - // Compression levels - val Z_NO_COMPRESSION: CompressionLevel = js.native - val Z_BEST_SPEED: CompressionLevel = js.native - val Z_BEST_COMPRESSION: CompressionLevel = js.native - val Z_DEFAULT_COMPRESSION: CompressionLevel = js.native - - // Compression strategies - val Z_FILTERED: CompressionStrategy = js.native - val Z_HUFFMAN_ONLY: CompressionStrategy = js.native - val Z_RLE: CompressionStrategy = js.native - val Z_FIXED: CompressionStrategy = js.native - val Z_DEFAULT_STRATEGY: CompressionStrategy = js.native - - // Possible values of the data_type field - val Z_BINARY: DataType = js.native - val Z_TEXT: DataType = js.native - val Z_ASCII: DataType = js.native - val Z_UNKNOWN: DataType = js.native - - // The deflate compression method (the only one supported in this version). - val Z_DEFLATED: DeflateCompressMethod = js.native + @enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs12) + def createBrotliCompress(options: BrotliOptions = js.native): BrotliCompress = js.native - // For initializing zalloc, zfree, opaque. - val Z_NULL: AllocationType = js.native - - ///////////////////////////////////////////////////////////////////////////////// - // Methods - ///////////////////////////////////////////////////////////////////////////////// + @enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs12) + def createBrotliDecompress(options: BrotliOptions = js.native): BrotliDecompress = js.native /** * Returns a new Deflate object with an options. @@ -110,155 +62,111 @@ trait Zlib extends IEventEmitter { */ def createUnzip(options: CompressionOptions = js.native): Unzip = js.native - /** - * Flush pending data. Don't call this frivolously, premature flushes negatively impact the effectiveness of the compression algorithm. - * @example zlib.flush([kind], callback) - */ - def flush(kind: CompressionFlush, callback: js.Function): Unit = js.native - - /** - * Flush pending data. Don't call this frivolously, premature flushes negatively impact the effectiveness of the compression algorithm. - * @example zlib.flush([kind], callback) - */ - def flush(callback: js.Function): Unit = js.native - - /** - * Dynamically update the compression level and compression strategy. Only applicable to deflate algorithm. - * @example zlib.params(level, strategy, callback) - */ - def params(level: CompressionLevel, strategy: CompressionStrategy, callback: js.Function): Unit = js.native - - /** - * Reset the compressor/decompressor to factory defaults. Only applicable to the inflate and deflate algorithms. - * @example zlib.reset() - */ - def reset(): Unit = js.native - ///////////////////////////////////////////////////////////////////////////////// // Convenience Methods ///////////////////////////////////////////////////////////////////////////////// - /** - * Compress a Buffer or string with Deflate. - * @example zlib.deflate(buf[, options], callback) - */ - def deflate(buf: Buffer | String, options: CompressionOptions, callback: js.Function): Unit = js.native + @enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs12) + def brotliCompress(buffer: Data, options: BrotliOptions, callback: js.Function): Unit = js.native + @enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs12) + def brotliCompress(buffer: Data, callback: js.Function): Unit = js.native + @enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs12) + def brotliCompressSync(buffer: Data, options: BrotliOptions = js.native): Unit = js.native + + @enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs12) + def brotliDecompress(buffer: Data, options: BrotliOptions, callback: js.Function): Unit = js.native + @enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs12) + def brotliDecompress(buffer: Data, callback: js.Function): Unit = js.native + @enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs12) + def brotliDecompressSync(buffer: Data, options: BrotliOptions = js.native): Unit = js.native /** * Compress a Buffer or string with Deflate. * @example zlib.deflate(buf[, options], callback) */ - def deflate(buf: Buffer | String, callback: js.Function): Unit = js.native + def deflate(buffer: Data, options: CompressionOptions, callback: js.Function): Unit = js.native + def deflate(buffer: Data, callback: js.Function): Unit = js.native /** * Compress a Buffer or string with Deflate. * @example zlib.deflateSync(buf[, options]) */ - def deflateSync(buf: Buffer | String, options: CompressionOptions = js.native): Unit = js.native + def deflateSync(buffer: Data, options: CompressionOptions = js.native): Unit = js.native /** * Compress a Buffer or string with DeflateRaw. * @example zlib.deflateRaw(buf[, options], callback) */ - def deflateRaw(buf: Buffer | String, options: CompressionOptions, callback: js.Function): Unit = + def deflateRaw(buffer: Data, options: CompressionOptions, callback: js.Function): Unit = js.native - - /** - * Compress a Buffer or string with DeflateRaw. - * @example zlib.deflateRaw(buf[, options], callback) - */ - def deflateRaw(buf: Buffer | String, callback: js.Function): Unit = js.native + def deflateRaw(buffer: Data, callback: js.Function): Unit = js.native + def deflateRawSync(buffer: Data, options: CompressionOptions = js.native): Unit = js.native /** * Decompress a Buffer or string with Gunzip. * @example zlib.gunzip(buf[, options], callback) */ - def gunzip(buf: Buffer | String, options: CompressionOptions, callback: js.Function): Unit = js.native - - /** - * Decompress a Buffer or string with Gunzip. - * @example zlib.gunzip(buf[, options], callback) - */ - def gunzip(buf: Buffer | String, callback: js.Function): Unit = js.native + def gunzip(buffer: Data, options: CompressionOptions, callback: js.Function): Unit = js.native + def gunzip(buffer: Data, callback: js.Function): Unit = js.native /** * Decompress a Buffer or string with Gunzip. * @example zlib.gunzipSync(buf[, options]) */ - def gunzipSync(buf: Buffer | String, options: CompressionOptions = js.native): Unit = js.native + def gunzipSync(buffer: Data, options: CompressionOptions = js.native): Unit = js.native /** * Compress a Buffer or string with Gzip. * @example zlib.gzip(buf[, options], callback) */ - def gzip(buf: Buffer | String, options: CompressionOptions, callback: js.Function): Unit = js.native - - /** - * Compress a Buffer or string with Gzip. - * @example zlib.gzip(buf[, options], callback) - */ - def gzip(buf: Buffer | String, callback: js.Function): Unit = js.native + def gzip(buffer: Data, options: CompressionOptions, callback: js.Function): Unit = js.native + def gzip(buffer: Data, callback: js.Function): Unit = js.native /** * Compress a Buffer or string with Gzip. * @example zlib.gzipSync(buf[, options]) */ - def gzipSync(buf: Buffer | String, options: CompressionOptions = js.native): Unit = js.native + def gzipSync(buffer: Data, options: CompressionOptions = js.native): Unit = js.native /** * Decompress a Buffer or string with Inflate. * @example zlib.inflate(buf[, options], callback) */ - def inflate(buf: Buffer | String, options: CompressionOptions, callback: js.Function): Unit = js.native - - /** - * Decompress a Buffer or string with Inflate. - * @example zlib.inflate(buf[, options], callback) - */ - def inflate(buf: Buffer | String, callback: js.Function): Unit = js.native + def inflate(buffer: Data, options: CompressionOptions, callback: js.Function): Unit = js.native + def inflate(buffer: Data, callback: js.Function): Unit = js.native /** * Decompress a Buffer or string with Inflate. * @example zlib.inflateSync(buf[, options]) */ - def inflateSync(buf: Buffer | String, options: CompressionOptions = js.native): Unit = js.native + def inflateSync(buffer: Data, options: CompressionOptions = js.native): Unit = js.native /** * Decompress a Buffer or string with InflateRaw. * @example zlib.inflateRaw(buf[, options], callback) */ - def inflateRaw(buf: Buffer | String, options: CompressionOptions, callback: js.Function): Unit = + def inflateRaw(buffer: Data, options: CompressionOptions, callback: js.Function): Unit = js.native - - /** - * Decompress a Buffer or string with InflateRaw. - * @example zlib.inflateRaw(buf[, options], callback) - */ - def inflateRaw(buf: Buffer | String, callback: js.Function): Unit = js.native + def inflateRaw(buffer: Data, callback: js.Function): Unit = js.native /** * Decompress a Buffer or string with InflateRaw. * @example zlib.inflateRawSync(buf[, options]) */ - def inflateRawSync(buf: Buffer | String, options: CompressionOptions = js.native): Unit = js.native - - /** - * Decompress a Buffer or string with Unzip. - * @example zlib.unzip(buf[, options], callback) - */ - def unzip(buf: Buffer | String, options: CompressionOptions, callback: js.Function): Unit = js.native + def inflateRawSync(buffer: Data, options: CompressionOptions = js.native): Unit = js.native /** * Decompress a Buffer or string with Unzip. * @example zlib.unzip(buf[, options], callback) */ - def unzip(buf: Buffer | String, callback: js.Function): Unit = js.native + def unzip(buffer: Data, options: CompressionOptions, callback: js.Function): Unit = js.native + def unzip(buffer: Data, callback: js.Function): Unit = js.native /** * Decompress a Buffer or string with Unzip. * @example zlib.unzipSync(buf[, options]) */ - def unzipSync(buf: Buffer | String, options: CompressionOptions = js.native): Unit = js.native + def unzipSync(buffer: Data, options: CompressionOptions = js.native): Unit = js.native } diff --git a/app/current/src/main/scala/io/scalajs/nodejs/zlib/ZlibBase.scala b/app/current/src/main/scala/io/scalajs/nodejs/zlib/ZlibBase.scala new file mode 100644 index 000000000..557a4a033 --- /dev/null +++ b/app/current/src/main/scala/io/scalajs/nodejs/zlib/ZlibBase.scala @@ -0,0 +1,26 @@ +package io.scalajs.nodejs.zlib + +import io.scalajs.nodejs.stream + +import scala.scalajs.js + +/** + * Not exported by the zlib module. + * It is documented here because it is the base class of the compressor/decompressor classes. + * + * This class inherits from stream.Transform, allowing zlib objects to be used in pipes and + * similar stream operations. + */ +@js.native +trait ZlibBase extends stream.Transform { + def bytesWritten: Double = js.native + + def close(callback: js.Function = js.native): Unit = js.native + + def flush(kind: CompressionFlush, callback: js.Function): Unit = js.native + def flush(callback: js.Function): Unit = js.native + + def params(level: CompressionLevel, strategy: CompressionStrategy, callback: js.Function): Unit = js.native + + def reset(): Unit = js.native +} diff --git a/app/current/src/main/scala/io/scalajs/nodejs/zlib/package.scala b/app/current/src/main/scala/io/scalajs/nodejs/zlib/package.scala index 388a991b9..b111f56c9 100644 --- a/app/current/src/main/scala/io/scalajs/nodejs/zlib/package.scala +++ b/app/current/src/main/scala/io/scalajs/nodejs/zlib/package.scala @@ -4,6 +4,7 @@ import io.scalajs.nodejs.buffer.Buffer import io.scalajs.util.PromiseHelper._ import scala.concurrent.Future +import scala.scalajs.js.typedarray.{ArrayBuffer, DataView, TypedArray} import scala.scalajs.js.| /** @@ -11,88 +12,76 @@ import scala.scalajs.js.| */ package object zlib { - type AllocationType = Integer - type CompressionFlush = Integer - type CompressionFunction = Integer - type CompressionLevel = Integer - type CompressionStrategy = Integer - type DataType = Integer - type DeflateCompressMethod = Integer + type Data = String | TypedArray[_, _] | DataView | ArrayBuffer + type AllocationType = Int + type CompressionFlush = Int + type CompressionFunction = Int + type CompressionLevel = Int + type CompressionStrategy = Int + type DataType = Int + type DeflateCompressMethod = Int + + @deprecated("Use ZlibBase instead", "0.9.0") + type CompressionAlgorithm = ZlibBase /** * Zlib Extensions */ - final implicit class ZlibExtensions(val zlib: Zlib) extends AnyVal { + implicit final class ZlibExtensions(val zlib: Zlib) extends AnyVal { /** * Asynchronously compresses a Buffer or string with Deflate. */ @inline - def deflateFuture(buf: Buffer | String, options: CompressionOptions = null): Future[Buffer] = { - promiseWithError1[Error, Buffer](zlib.deflate(buf, options, _)) + def deflateFuture(buffer: Data, options: CompressionOptions = null): Future[Buffer] = { + promiseWithError1[Error, Buffer](zlib.deflate(buffer, options, _)) } /** * Asynchronously compresses a Buffer or string with DeflateRaw. */ @inline - def deflateRawFuture(buf: Buffer | String, options: CompressionOptions = null): Future[Buffer] = { - promiseWithError1[Error, Buffer](zlib.deflateRaw(buf, options, _)) + def deflateRawFuture(buffer: Data, options: CompressionOptions = null): Future[Buffer] = { + promiseWithError1[Error, Buffer](zlib.deflateRaw(buffer, options, _)) } - /** - * Flush pending data. Don't call this frivolously, premature flushes negatively impact the effectiveness of the compression algorithm. - */ - @inline - def flushFuture(kind: CompressionFlush = null): Future[Buffer] = - promiseWithError1[Error, Buffer](zlib.flush(kind, _)) - /** * Compress a Buffer or string with Gzip. */ @inline - def gzipFuture(buf: Buffer | String, options: CompressionOptions = null): Future[Buffer] = { - promiseWithError1[Error, Buffer](zlib.gzip(buf, options, _)) + def gzipFuture(buffer: Data, options: CompressionOptions = null): Future[Buffer] = { + promiseWithError1[Error, Buffer](zlib.gzip(buffer, options, _)) } /** * Decompress a Buffer or string with Gunzip. */ @inline - def gunzipFuture(buf: Buffer | String, options: CompressionOptions = null): Future[Buffer] = { - promiseWithError1[Error, Buffer](zlib.gunzip(buf, options, _)) + def gunzipFuture(buffer: Data, options: CompressionOptions = null): Future[Buffer] = { + promiseWithError1[Error, Buffer](zlib.gunzip(buffer, options, _)) } /** * Decompress a Buffer or string with Inflate. */ @inline - def inflateFuture(buf: Buffer | String, options: CompressionOptions = null): Future[Buffer] = { - promiseWithError1[Error, Buffer](zlib.inflate(buf, options, _)) + def inflateFuture(buffer: Data, options: CompressionOptions = null): Future[Buffer] = { + promiseWithError1[Error, Buffer](zlib.inflate(buffer, options, _)) } /** * Decompress a Buffer or string with InflateRaw. */ - def inflateRawFuture(buf: Buffer | String, options: CompressionOptions = null): Future[Buffer] = { - promiseWithError1[Error, Buffer](zlib.inflateRaw(buf, options, _)) - } - - /** - * Dynamically update the compression level and compression strategy. Only applicable to deflate algorithm. - * @example zlib.params(level, strategy, callback) - */ - @inline - def paramsFuture(level: CompressionLevel, strategy: CompressionStrategy): Future[Buffer] = { - promiseWithError1[Error, Buffer](zlib.params(level, strategy, _)) + def inflateRawFuture(buffer: Data, options: CompressionOptions = null): Future[Buffer] = { + promiseWithError1[Error, Buffer](zlib.inflateRaw(buffer, options, _)) } /** * Decompress a Buffer or string with Unzip. */ @inline - def unzipFuture(buf: Buffer | String, options: CompressionOptions = null): Future[Buffer] = { - promiseWithError1[Error, Buffer](zlib.unzip(buf, options, _)) + def unzipFuture(buffer: Data, options: CompressionOptions = null): Future[Buffer] = { + promiseWithError1[Error, Buffer](zlib.unzip(buffer, options, _)) } }