From 30ed12ea616875c90f4cbb4835ee5feaa889bb85 Mon Sep 17 00:00:00 2001 From: Veit Heller Date: Thu, 27 Jan 2022 11:55:55 +0100 Subject: [PATCH] fix for newest carp --- README.md | 2 +- docs/ZLib.html | 177 +++++++++++++++++++++++++++---------------------- zlib.carp | 8 +-- zlib_helper.h | 12 ++-- 4 files changed, 106 insertions(+), 93 deletions(-) diff --git a/README.md b/README.md index 8e00b50..3aaa6d8 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docs/ZLib.html b/docs/ZLib.html index 7b4f578..6feb182 100644 --- a/docs/ZLib.html +++ b/docs/ZLib.html @@ -18,20 +18,32 @@
-

- ZLib -

-
-

is a high-level wrapper around zlib.

+
+

+ ZLib +

+
+

is a high-level wrapper around zlib.

Installation

-
(load "https://veitheller.de/git/carpentry/zlib.git@0.0.1")
+
(load "git@git.veitheller.de:carpentry/zlib.git@0.0.2")
 

Usage

The ZLib module provides only two functions, inflate and @@ -55,98 +67,101 @@ levels are defined in ZLib.ZLevel, and are BestSpeed, BestCompression, and DefaultCompression, which is, well, the default.

-
-
- -

- ZLevel -

-
-
- module
-

- Module -

- - - -

-

is a type used in conjunction with +

+ +

+ + ZLevel + +

+ +
+ module +
+

+ Module +

+ + + +

+

is a type used in conjunction with deflate-with. It controls the compression level.

The constructors are NoCompression, BestSpeed, BestCompression, and DefaultCompression, which is, well, the default.

-

-
-
- -

- deflate -

-
-
- defn +

-

- (Fn [(Ref String a)] (Result ZBytes String)) -

-
-                    (deflate s)
-                
-

-

takes a bytes object s and returns a Result.

+
+ +

+ deflate +

+
+
+ defn +
+

+ (Fn [(Ref String a)] (Result ZLib.ZBytes String)) +

+
+                        (deflate s)
+                    
+

+

takes a bytes object s and returns a Result.

The Result will be a Success containing the deflated bytes if all goes well, and an Error returning an error message otherwise.

It is equivalent to calling deflate-with with (ZLevel.DefaultCompression).

-

-
-
- -

- deflate-with -

-
-
- defn +

-

- (Fn [(Ref String a), ZLib.ZLevel] (Result ZBytes String)) -

-
-                    (deflate-with s level)
-                
-

-

takes a bytes object s, a Zlevel level and returns +

+ +

+ deflate-with +

+
+
+ defn +
+

+ (Fn [(Ref String a), ZLib.ZLevel] (Result ZLib.ZBytes String)) +

+
+                        (deflate-with s level)
+                    
+

+

takes a bytes object s, a Zlevel level and returns a Result.

The Result will be a Success containing the deflated bytes if all goes well, and an Error returning an error message otherwise.

-

-
-
- -

- inflate -

-
-
- defn +

-

- (Fn [ZBytes] (Result String String)) -

-
-                    (inflate s)
-                
-

-

takes a bytes object s and returns a Result.

+
+ +

+ inflate +

+
+
+ defn +
+

+ (Fn [ZLib.ZBytes] (Result String String)) +

+
+                        (inflate s)
+                    
+

+

takes a bytes object s and returns a Result.

The Result will be a Success containing the inflated string if all goes well, and an Error returning an error message otherwise.

-

+

+
diff --git a/zlib.carp b/zlib.carp index d87608a..eb20094 100644 --- a/zlib.carp +++ b/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 @@ -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 diff --git a/zlib_helper.h b/zlib_helper.h index a51c7c0..e8b9a62 100644 --- a/zlib_helper.h +++ b/zlib_helper.h @@ -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;