fix for newest carp

This commit is contained in:
2022-01-27 11:55:55 +01:00
parent b91b26f586
commit 30ed12ea61
4 changed files with 106 additions and 93 deletions

View File

@@ -5,7 +5,7 @@ is a high-level wrapper around [zlib](https://zlib.net/).
## Installation
```clojure
(load "https://veitheller.de/git/carpentry/zlib.git@0.0.1")
(load "git@git.veitheller.de:carpentry/zlib.git@0.0.2")
```
## Usage

View File

@@ -18,20 +18,32 @@
<div class="index">
<ul>
<li>
<a href="ZLib.html">
ZLib
</a>
<details>
<summary>
<a href="ZLib.html">
ZLib
</a>
</summary>
<ul>
<li>
<a href="ZLib.ZLevel.html">
ZLevel
</a>
</li>
</ul>
</details>
</li>
</ul>
</div>
</div>
<h1>
ZLib
</h1>
<div class="module-description">
<p>is a high-level wrapper around <a href="https://zlib.net/">zlib</a>.</p>
<div class="module">
<h1>
ZLib
</h1>
<div class="module-description">
<p>is a high-level wrapper around <a href="https://zlib.net/">zlib</a>.</p>
<h2>Installation</h2>
<pre><code class="language-clojure">(load &quot;https://veitheller.de/git/carpentry/zlib.git@0.0.1&quot;)
<pre><code class="language-clojure">(load &quot;git@git.veitheller.de:carpentry/zlib.git@0.0.2&quot;)
</code></pre>
<h2>Usage</h2>
<p>The <code>ZLib</code> module provides only two functions, <a href="#inflate"><code>inflate</code></a> and
@@ -55,98 +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
default.</p>
</div>
<div class="binder">
<a class="anchor" href="#ZLevel">
<h3 id="ZLevel">
ZLevel
</h3>
</a>
<div class="description">
module
</div>
<p class="sig">
Module
</p>
<span>
</span>
<p class="doc">
<p>is a type used in conjunction with
<div class="binder">
<a class="anchor" href="#ZLevel">
<h3 id="ZLevel">
<a href="ZLib.ZLevel.html">
ZLevel
</a>
</h3>
</a>
<div class="description">
module
</div>
<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>
<p>The constructors are <code>NoCompression</code>, <code>BestSpeed</code>, <code>BestCompression</code>, and
<code>DefaultCompression</code>, which is, well, the default.</p>
</p>
</div>
<div class="binder">
<a class="anchor" href="#deflate">
<h3 id="deflate">
deflate
</h3>
</a>
<div class="description">
defn
</p>
</div>
<p class="sig">
(Fn [(Ref String a)] (Result 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>
<div class="binder">
<a class="anchor" href="#deflate">
<h3 id="deflate">
deflate
</h3>
</a>
<div class="description">
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
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
<code>(ZLevel.DefaultCompression)</code>.</p>
</p>
</div>
<div class="binder">
<a class="anchor" href="#deflate-with">
<h3 id="deflate-with">
deflate-with
</h3>
</a>
<div class="description">
defn
</p>
</div>
<p class="sig">
(Fn [(Ref String a), ZLib.ZLevel] (Result 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
<div class="binder">
<a class="anchor" href="#deflate-with">
<h3 id="deflate-with">
deflate-with
</h3>
</a>
<div class="description">
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>
<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>
</p>
</div>
<div class="binder">
<a class="anchor" href="#inflate">
<h3 id="inflate">
inflate
</h3>
</a>
<div class="description">
defn
</p>
</div>
<p class="sig">
(Fn [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>
<div class="binder">
<a class="anchor" href="#inflate">
<h3 id="inflate">
inflate
</h3>
</a>
<div class="description">
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
well, and an <code>Error</code> returning an error message otherwise.</p>
</p>
</p>
</div>
</div>
</div>
</body>

View File

@@ -7,7 +7,7 @@
## Installation
```clojure
(load \"https://veitheller.de/git/carpentry/zlib.git@0.0.1\")
(load \"git@git.veitheller.de:carpentry/zlib.git@0.0.2\")
```
## Usage
@@ -45,17 +45,15 @@ default.")
len Int
bytes String
])
(private ZBytes)
(hidden ZBytes)
(register-type ZRes)
(defmodule ZRes
(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 err (Fn [ZRes] String) "ZRes_err")
)
(private ZRes)
(hidden ZRes)
(deftype ZLevel
@@ -80,7 +78,7 @@ The constructors are `NoCompression`, `BestSpeed`, `BestCompression`, and
(private 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`.
The `Result` will be a `Success` containing the inflated string if all goes

View File

@@ -5,13 +5,13 @@
typedef struct {
int len;
char* bytes;
} ZBytes;
} ZLibZBytes;
typedef struct {
int which;
union {
int err;
ZBytes* out;
ZLibZBytes* out;
};
} ZRes;
#define ZRES_OK 0
@@ -21,7 +21,7 @@ bool ZRes_is_ok(ZRes* r) {
return r->which == ZRES_OK;
}
ZBytes ZRes_bytes(ZRes r) {
ZLibZBytes ZRes_bytes(ZRes r) {
assert(r.which == ZRES_OK);
return *r.out;
}
@@ -63,7 +63,7 @@ char* ZRes_err(ZRes r) {
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; })
ZRes ZLib_inflate_c(ZBytes b) {
ZRes ZLib_inflate_c(ZLibZBytes b) {
int ret;
ZRes res;
unsigned have;
@@ -73,7 +73,7 @@ ZRes ZLib_inflate_c(ZBytes b) {
int offs = 0;
int len = b.len;
char* source = b.bytes;
ZBytes* bytes = malloc(sizeof(ZBytes));
ZLibZBytes* bytes = malloc(sizeof(ZLibZBytes));
bytes->bytes = NULL;
bytes->len = 0;
@@ -143,7 +143,7 @@ ZRes ZLib_deflate_c(String* s, int level) {
unsigned char out[CHUNK];
int offs = 0;
int len = strlen(*s);
ZBytes* bytes = malloc(sizeof(ZBytes));
ZLibZBytes* bytes = malloc(sizeof(ZLibZBytes));
bytes->bytes = NULL;
bytes->len = 0;