Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
30ed12ea61 | |||
b91b26f586 | |||
5c3368f953 |
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2020 Veit Heller
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
@@ -5,7 +5,7 @@ is a high-level wrapper around [zlib](https://zlib.net/).
|
|||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```clojure
|
```clojure
|
||||||
(load "https://veitheller.de/git/carpentry/zlib.git@0.0.1")
|
(load "git@git.veitheller.de:carpentry/zlib.git@0.0.2")
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
202
docs/ZLib.html
202
docs/ZLib.html
@@ -4,13 +4,13 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="../style.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="logo">
|
<div class="logo">
|
||||||
<a href="http://github.com/carp-lang/Carp">
|
<a href="">
|
||||||
<img src="logo.png">
|
<img src="">
|
||||||
</a>
|
</a>
|
||||||
<div class="title">
|
<div class="title">
|
||||||
zlib
|
zlib
|
||||||
@@ -18,20 +18,32 @@
|
|||||||
<div class="index">
|
<div class="index">
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<a href="ZLib.html">
|
<details>
|
||||||
ZLib
|
<summary>
|
||||||
</a>
|
<a href="ZLib.html">
|
||||||
|
ZLib
|
||||||
|
</a>
|
||||||
|
</summary>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a href="ZLib.ZLevel.html">
|
||||||
|
ZLevel
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</details>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<h1>
|
<div class="module">
|
||||||
ZLib
|
<h1>
|
||||||
</h1>
|
ZLib
|
||||||
<div class="module-description">
|
</h1>
|
||||||
<p>is a high-level wrapper around <a href="https://zlib.net/">zlib</a>.</p>
|
<div class="module-description">
|
||||||
|
<p>is a high-level wrapper around <a href="https://zlib.net/">zlib</a>.</p>
|
||||||
<h2>Installation</h2>
|
<h2>Installation</h2>
|
||||||
<pre><code class="language-clojure">(load "https://veitheller.de/git/carpentry/zlib.git@0.0.1")
|
<pre><code class="language-clojure">(load "git@git.veitheller.de:carpentry/zlib.git@0.0.2")
|
||||||
</code></pre>
|
</code></pre>
|
||||||
<h2>Usage</h2>
|
<h2>Usage</h2>
|
||||||
<p>The <code>ZLib</code> module provides only two functions, <a href="#inflate"><code>inflate</code></a> and
|
<p>The <code>ZLib</code> module provides only two functions, <a href="#inflate"><code>inflate</code></a> and
|
||||||
@@ -55,117 +67,101 @@ levels are defined in <a href="#ZLevel"><code>ZLib.ZLevel</code></a>, and are <c
|
|||||||
<code>BestSpeed</code>, <code>BestCompression</code>, and <code>DefaultCompression</code>, which is, well, the
|
<code>BestSpeed</code>, <code>BestCompression</code>, and <code>DefaultCompression</code>, which is, well, the
|
||||||
default.</p>
|
default.</p>
|
||||||
|
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#ZBytes">
|
|
||||||
<h3 id="ZBytes">
|
|
||||||
ZBytes
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
module
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
Module
|
<a class="anchor" href="#ZLevel">
|
||||||
</p>
|
<h3 id="ZLevel">
|
||||||
<span>
|
<a href="ZLib.ZLevel.html">
|
||||||
|
ZLevel
|
||||||
</span>
|
</a>
|
||||||
<p class="doc">
|
</h3>
|
||||||
|
</a>
|
||||||
</p>
|
<div class="description">
|
||||||
</div>
|
module
|
||||||
<div class="binder">
|
</div>
|
||||||
<a class="anchor" href="#ZLevel">
|
<p class="sig">
|
||||||
<h3 id="ZLevel">
|
Module
|
||||||
ZLevel
|
</p>
|
||||||
</h3>
|
<span>
|
||||||
</a>
|
|
||||||
<div class="description">
|
</span>
|
||||||
module
|
<p class="doc">
|
||||||
</div>
|
<p>is a type used in conjunction with
|
||||||
<p class="sig">
|
|
||||||
Module
|
|
||||||
</p>
|
|
||||||
<span>
|
|
||||||
|
|
||||||
</span>
|
|
||||||
<p class="doc">
|
|
||||||
<p>is a type used in conjunction with
|
|
||||||
<a href="#deflate-with"><code>deflate-with</code></a>. It controls the compression level.</p>
|
<a href="#deflate-with"><code>deflate-with</code></a>. It controls the compression level.</p>
|
||||||
<p>The constructors are <code>NoCompression</code>, <code>BestSpeed</code>, <code>BestCompression</code>, and
|
<p>The constructors are <code>NoCompression</code>, <code>BestSpeed</code>, <code>BestCompression</code>, and
|
||||||
<code>DefaultCompression</code>, which is, well, the default.</p>
|
<code>DefaultCompression</code>, which is, well, the default.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#deflate">
|
|
||||||
<h3 id="deflate">
|
|
||||||
deflate
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
defn
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
(λ [&String] (Result ZBytes String))
|
<a class="anchor" href="#deflate">
|
||||||
</p>
|
<h3 id="deflate">
|
||||||
<pre class="args">
|
deflate
|
||||||
(deflate s)
|
</h3>
|
||||||
</pre>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
<p>takes a bytes object <code>s</code> and returns a <code>Result</code>.</p>
|
defn
|
||||||
|
</div>
|
||||||
|
<p class="sig">
|
||||||
|
(Fn [(Ref String a)] (Result ZLib.ZBytes String))
|
||||||
|
</p>
|
||||||
|
<pre class="args">
|
||||||
|
(deflate s)
|
||||||
|
</pre>
|
||||||
|
<p class="doc">
|
||||||
|
<p>takes a bytes object <code>s</code> and returns a <code>Result</code>.</p>
|
||||||
<p>The <code>Result</code> will be a <code>Success</code> containing the deflated bytes if all goes
|
<p>The <code>Result</code> will be a <code>Success</code> containing the deflated bytes if all goes
|
||||||
well, and an <code>Error</code> returning an error message otherwise.</p>
|
well, and an <code>Error</code> returning an error message otherwise.</p>
|
||||||
<p>It is equivalent to calling <a href="#deflate-with"><code>deflate-with</code></a> with
|
<p>It is equivalent to calling <a href="#deflate-with"><code>deflate-with</code></a> with
|
||||||
<code>(ZLevel.DefaultCompression)</code>.</p>
|
<code>(ZLevel.DefaultCompression)</code>.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#deflate-with">
|
|
||||||
<h3 id="deflate-with">
|
|
||||||
deflate-with
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
defn
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
(λ [&String, ZLevel] (Result ZBytes String))
|
<a class="anchor" href="#deflate-with">
|
||||||
</p>
|
<h3 id="deflate-with">
|
||||||
<pre class="args">
|
deflate-with
|
||||||
(deflate-with s level)
|
</h3>
|
||||||
</pre>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
<p>takes a bytes object <code>s</code>, a <code>Zlevel</code> <code>level</code> and returns
|
defn
|
||||||
|
</div>
|
||||||
|
<p class="sig">
|
||||||
|
(Fn [(Ref String a), ZLib.ZLevel] (Result ZLib.ZBytes String))
|
||||||
|
</p>
|
||||||
|
<pre class="args">
|
||||||
|
(deflate-with s level)
|
||||||
|
</pre>
|
||||||
|
<p class="doc">
|
||||||
|
<p>takes a bytes object <code>s</code>, a <code>Zlevel</code> <code>level</code> and returns
|
||||||
a <code>Result</code>.</p>
|
a <code>Result</code>.</p>
|
||||||
<p>The <code>Result</code> will be a <code>Success</code> containing the deflated bytes if all goes
|
<p>The <code>Result</code> will be a <code>Success</code> containing the deflated bytes if all goes
|
||||||
well, and an <code>Error</code> returning an error message otherwise.</p>
|
well, and an <code>Error</code> returning an error message otherwise.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
<div class="binder">
|
|
||||||
<a class="anchor" href="#inflate">
|
|
||||||
<h3 id="inflate">
|
|
||||||
inflate
|
|
||||||
</h3>
|
|
||||||
</a>
|
|
||||||
<div class="description">
|
|
||||||
defn
|
|
||||||
</div>
|
</div>
|
||||||
<p class="sig">
|
<div class="binder">
|
||||||
(λ [ZBytes] (Result String String))
|
<a class="anchor" href="#inflate">
|
||||||
</p>
|
<h3 id="inflate">
|
||||||
<pre class="args">
|
inflate
|
||||||
(inflate s)
|
</h3>
|
||||||
</pre>
|
</a>
|
||||||
<p class="doc">
|
<div class="description">
|
||||||
<p>takes a bytes object <code>s</code> and returns a <code>Result</code>.</p>
|
defn
|
||||||
|
</div>
|
||||||
|
<p class="sig">
|
||||||
|
(Fn [ZLib.ZBytes] (Result String String))
|
||||||
|
</p>
|
||||||
|
<pre class="args">
|
||||||
|
(inflate s)
|
||||||
|
</pre>
|
||||||
|
<p class="doc">
|
||||||
|
<p>takes a bytes object <code>s</code> and returns a <code>Result</code>.</p>
|
||||||
<p>The <code>Result</code> will be a <code>Success</code> containing the inflated string if all goes
|
<p>The <code>Result</code> will be a <code>Success</code> containing the inflated string if all goes
|
||||||
well, and an <code>Error</code> returning an error message otherwise.</p>
|
well, and an <code>Error</code> returning an error message otherwise.</p>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
15
gendocs.carp
15
gendocs.carp
@@ -1,13 +1,10 @@
|
|||||||
(load "zlib.carp")
|
(load "zlib.carp")
|
||||||
|
|
||||||
(defndynamic gendocs []
|
(Project.config "title" "zlib")
|
||||||
(do
|
(Project.config "docs-directory" "./docs/")
|
||||||
(Project.config "title" "zlib")
|
(Project.config "docs-logo" "")
|
||||||
(Project.config "docs-directory" "./docs/")
|
(Project.config "docs-styling" "../style.css")
|
||||||
(Project.config "docs-logo" "")
|
(Project.config "docs-generate-index" false)
|
||||||
(Project.config "docs-styling" "style.css")
|
(save-docs ZLib)
|
||||||
(Project.config "docs-generate-index" false)
|
|
||||||
(save-docs ZLib)))
|
|
||||||
|
|
||||||
(gendocs)
|
|
||||||
(quit)
|
(quit)
|
||||||
|
21
zlib.carp
21
zlib.carp
@@ -7,7 +7,7 @@
|
|||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```clojure
|
```clojure
|
||||||
(load \"https://veitheller.de/git/carpentry/zlib.git@0.0.1\")
|
(load \"git@git.veitheller.de:carpentry/zlib.git@0.0.2\")
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@@ -41,27 +41,21 @@ default.")
|
|||||||
; i tried doing this in carp, but it’s a bit of a pain to wrap the API
|
; i tried doing this in carp, but it’s a bit of a pain to wrap the API
|
||||||
; idiomatically, so for now you’ll only get regular inflation and deflation
|
; idiomatically, so for now you’ll only get regular inflation and deflation
|
||||||
(defmodule ZLib
|
(defmodule ZLib
|
||||||
(doc ZBytes "is an opaque bytes type with an associated length.")
|
|
||||||
(register-type ZBytes [
|
(register-type ZBytes [
|
||||||
len Int
|
len Int
|
||||||
bytes String
|
bytes String
|
||||||
])
|
])
|
||||||
|
(hidden ZBytes)
|
||||||
|
|
||||||
(private ZRes)
|
|
||||||
(hidden ZRes)
|
|
||||||
(register-type ZRes)
|
(register-type ZRes)
|
||||||
(defmodule ZRes
|
(defmodule ZRes
|
||||||
(register ok? (Fn [&ZRes] Bool) "ZRes_is_ok")
|
(register ok? (Fn [&ZRes] Bool) "ZRes_is_ok")
|
||||||
(register bytes (Fn [ZRes] ZBytes) "ZRes_bytes")
|
(register bytes (Fn [ZRes] ZLib.ZBytes) "ZRes_bytes")
|
||||||
(register str (Fn [ZRes] String) "ZRes_str")
|
(register str (Fn [ZRes] String) "ZRes_str")
|
||||||
(register err (Fn [ZRes] String) "ZRes_err")
|
(register err (Fn [ZRes] String) "ZRes_err")
|
||||||
)
|
)
|
||||||
|
(hidden ZRes)
|
||||||
|
|
||||||
(doc ZLevel "is a type used in conjunction with
|
|
||||||
[`deflate-with`](#deflate-with). It controls the compression level.
|
|
||||||
|
|
||||||
The constructors are `NoCompression`, `BestSpeed`, `BestCompression`, and
|
|
||||||
`DefaultCompression`, which is, well, the default.")
|
|
||||||
(deftype ZLevel
|
(deftype ZLevel
|
||||||
(NoCompression [])
|
(NoCompression [])
|
||||||
(BestSpeed [])
|
(BestSpeed [])
|
||||||
@@ -76,10 +70,15 @@ The constructors are `NoCompression`, `BestSpeed`, `BestCompression`, and
|
|||||||
(BestSpeed) 1
|
(BestSpeed) 1
|
||||||
(BestCompression) 9
|
(BestCompression) 9
|
||||||
(DefaultCompression) -1)))
|
(DefaultCompression) -1)))
|
||||||
|
(doc ZLevel "is a type used in conjunction with
|
||||||
|
[`deflate-with`](#deflate-with). It controls the compression level.
|
||||||
|
|
||||||
|
The constructors are `NoCompression`, `BestSpeed`, `BestCompression`, and
|
||||||
|
`DefaultCompression`, which is, well, the default.")
|
||||||
|
|
||||||
(private inflate-)
|
(private inflate-)
|
||||||
(hidden inflate-)
|
(hidden inflate-)
|
||||||
(register inflate- (Fn [ZBytes] ZRes) "ZLib_inflate_c")
|
(register inflate- (Fn [ZLib.ZBytes] ZRes) "ZLib_inflate_c")
|
||||||
(doc inflate "takes a bytes object `s` and returns a `Result`.
|
(doc inflate "takes a bytes object `s` and returns a `Result`.
|
||||||
|
|
||||||
The `Result` will be a `Success` containing the inflated string if all goes
|
The `Result` will be a `Success` containing the inflated string if all goes
|
||||||
|
@@ -5,13 +5,13 @@
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
int len;
|
int len;
|
||||||
char* bytes;
|
char* bytes;
|
||||||
} ZBytes;
|
} ZLibZBytes;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int which;
|
int which;
|
||||||
union {
|
union {
|
||||||
int err;
|
int err;
|
||||||
ZBytes* out;
|
ZLibZBytes* out;
|
||||||
};
|
};
|
||||||
} ZRes;
|
} ZRes;
|
||||||
#define ZRES_OK 0
|
#define ZRES_OK 0
|
||||||
@@ -21,7 +21,7 @@ bool ZRes_is_ok(ZRes* r) {
|
|||||||
return r->which == ZRES_OK;
|
return r->which == ZRES_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZBytes ZRes_bytes(ZRes r) {
|
ZLibZBytes ZRes_bytes(ZRes r) {
|
||||||
assert(r.which == ZRES_OK);
|
assert(r.which == ZRES_OK);
|
||||||
return *r.out;
|
return *r.out;
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ char* ZRes_err(ZRes r) {
|
|||||||
__typeof__ (b) _b = (b); \
|
__typeof__ (b) _b = (b); \
|
||||||
_a < _b ? _a : _b; })
|
_a < _b ? _a : _b; })
|
||||||
|
|
||||||
ZRes ZLib_inflate_c(ZBytes b) {
|
ZRes ZLib_inflate_c(ZLibZBytes b) {
|
||||||
int ret;
|
int ret;
|
||||||
ZRes res;
|
ZRes res;
|
||||||
unsigned have;
|
unsigned have;
|
||||||
@@ -73,7 +73,7 @@ ZRes ZLib_inflate_c(ZBytes b) {
|
|||||||
int offs = 0;
|
int offs = 0;
|
||||||
int len = b.len;
|
int len = b.len;
|
||||||
char* source = b.bytes;
|
char* source = b.bytes;
|
||||||
ZBytes* bytes = malloc(sizeof(ZBytes));
|
ZLibZBytes* bytes = malloc(sizeof(ZLibZBytes));
|
||||||
bytes->bytes = NULL;
|
bytes->bytes = NULL;
|
||||||
bytes->len = 0;
|
bytes->len = 0;
|
||||||
|
|
||||||
@@ -143,7 +143,7 @@ ZRes ZLib_deflate_c(String* s, int level) {
|
|||||||
unsigned char out[CHUNK];
|
unsigned char out[CHUNK];
|
||||||
int offs = 0;
|
int offs = 0;
|
||||||
int len = strlen(*s);
|
int len = strlen(*s);
|
||||||
ZBytes* bytes = malloc(sizeof(ZBytes));
|
ZLibZBytes* bytes = malloc(sizeof(ZLibZBytes));
|
||||||
bytes->bytes = NULL;
|
bytes->bytes = NULL;
|
||||||
bytes->len = 0;
|
bytes->len = 0;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user