-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Pako.scala
69 lines (54 loc) · 2.15 KB
/
Pako.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package japgolly.webapputil.binary
import scala.annotation.nowarn
import scala.scalajs.js
import scala.scalajs.js.typedarray.Uint8Array
import scala.scalajs.js.|
/** Facade for the JS `pako` library with provides zlib compression & decompression. */
@js.native
@nowarn("msg=dead|never used")
sealed trait Pako extends js.Object {
import Pako._
def deflate(data: Data, options: DeflateOptions = js.native): Data = js.native
/** The same as deflate, but creates raw data, without wrapper (header and adler32 crc). */
def deflateRaw(data: Data, options: DeflateOptions = js.native): Data = js.native
/** Throws an exception on error */
def inflate(data: Data, options: InflateOptions = js.native): Data = js.native
/** The same as inflate, but creates raw data, without wrapper (header and adler32 crc).
*
* Throws an exception on error.
*/
def inflateRaw(data: Data, options: InflateOptions = js.native): Data = js.native
}
@nowarn("msg=dead|never used")
object Pako {
type Data = Uint8Array | js.Array[Int] | String
/** See http://zlib.net/manual.html#Advanced */
@js.native
trait DeflateOptions extends js.Object {
/** Z_NO_COMPRESSION: 0
* Z_BEST_SPEED: 1
* Z_BEST_COMPRESSION: 9
* Z_DEFAULT_COMPRESSION: -1
*/
var level : js.UndefOr[Int] = js.native
var windowBits: js.UndefOr[Int] = js.native
var memLevel : js.UndefOr[Int] = js.native
var strategy : js.UndefOr[Int] = js.native
var dictionary: js.UndefOr[Int] = js.native
}
@js.native
trait InflateOptions extends js.Object {
var windowBits: js.UndefOr[Int] = js.native
}
// ===================================================================================================================
def global: Pako =
apply(js.Dynamic.global.pako)
def apply(jsInstance: Any): Pako = {
assert(js.typeOf(jsInstance) == "object", "JS object expected. Got: " + jsInstance)
val d = jsInstance.asInstanceOf[js.Dynamic]
assert(js.typeOf(d.deflate) == "function", ".deflate is not a function")
force(jsInstance)
}
def force(jsInstance: Any): Pako =
jsInstance.asInstanceOf[Pako]
}