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
|
||||
|
||||
```clojure
|
||||
(load "https://veitheller.de/git/carpentry/zlib.git@0.0.1")
|
||||
(load "git@git.veitheller.de:carpentry/zlib.git@0.0.2")
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
200
docs/ZLib.html
200
docs/ZLib.html
@@ -4,13 +4,13 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<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>
|
||||
<body>
|
||||
<div class="content">
|
||||
<div class="logo">
|
||||
<a href="http://github.com/carp-lang/Carp">
|
||||
<img src="logo.png">
|
||||
<a href="">
|
||||
<img src="">
|
||||
</a>
|
||||
<div class="title">
|
||||
zlib
|
||||
@@ -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 "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>
|
||||
<h2>Usage</h2>
|
||||
<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
|
||||
default.</p>
|
||||
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#ZBytes">
|
||||
<h3 id="ZBytes">
|
||||
ZBytes
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
module
|
||||
</div>
|
||||
<p class="sig">
|
||||
Module
|
||||
</p>
|
||||
<span>
|
||||
<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>
|
||||
</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
|
||||
</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">
|
||||
(λ [&String] (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">
|
||||
(λ [&String, 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">
|
||||
(λ [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>
|
||||
|
15
gendocs.carp
15
gendocs.carp
@@ -1,13 +1,10 @@
|
||||
(load "zlib.carp")
|
||||
|
||||
(defndynamic gendocs []
|
||||
(do
|
||||
(Project.config "title" "zlib")
|
||||
(Project.config "docs-directory" "./docs/")
|
||||
(Project.config "docs-logo" "")
|
||||
(Project.config "docs-styling" "style.css")
|
||||
(Project.config "docs-generate-index" false)
|
||||
(save-docs ZLib)))
|
||||
(Project.config "title" "zlib")
|
||||
(Project.config "docs-directory" "./docs/")
|
||||
(Project.config "docs-logo" "")
|
||||
(Project.config "docs-styling" "../style.css")
|
||||
(Project.config "docs-generate-index" false)
|
||||
(save-docs ZLib)
|
||||
|
||||
(gendocs)
|
||||
(quit)
|
||||
|
21
zlib.carp
21
zlib.carp
@@ -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
|
||||
@@ -41,27 +41,21 @@ default.")
|
||||
; 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
|
||||
(defmodule ZLib
|
||||
(doc ZBytes "is an opaque bytes type with an associated length.")
|
||||
(register-type ZBytes [
|
||||
len Int
|
||||
bytes String
|
||||
])
|
||||
(hidden ZBytes)
|
||||
|
||||
(private ZRes)
|
||||
(hidden ZRes)
|
||||
(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")
|
||||
)
|
||||
(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
|
||||
(NoCompression [])
|
||||
(BestSpeed [])
|
||||
@@ -76,10 +70,15 @@ The constructors are `NoCompression`, `BestSpeed`, `BestCompression`, and
|
||||
(BestSpeed) 1
|
||||
(BestCompression) 9
|
||||
(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-)
|
||||
(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
|
||||
|
@@ -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;
|
||||
|
||||
|
Reference in New Issue
Block a user