summaryrefslogtreecommitdiff
path: root/src/compress.c
diff options
context:
space:
mode:
authorjakob <jakob@memeware.net>2017-05-14 19:07:06 -0400
committerjakob <jakob@memeware.net>2017-05-14 19:07:06 -0400
commit2ba0b505ce1ee748f42a85f7e27906737fa47fc8 (patch)
treeeacdebd8beae803b8c04c41d93ccb0dc8d45e35a /src/compress.c
parent41a7566c121a865b460649390a75473ac71eff1f (diff)
Initial data dumping functionality.
Diffstat (limited to 'src/compress.c')
-rw-r--r--src/compress.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/compress.c b/src/compress.c
index 578441b..47acb74 100644
--- a/src/compress.c
+++ b/src/compress.c
@@ -17,10 +17,14 @@
You should have received a copy of the GNU General Public License
along with Nekopack. If not, see <http://www.gnu.org/licenses/>. */
+#include <stdlib.h>
+
#include <zlib.h>
#include "io.h"
+#define LEVEL -1
+
/* Inflates `s` into a newly allocated stream structure. */
struct stream *stream_inflate(struct stream *s, size_t len,
@@ -56,3 +60,29 @@ struct stream *stream_inflate(struct stream *s, size_t len,
inflateEnd(&strm);
return n;
}
+
+
+/* Deflates `s` into a newly allocated stream structure. */
+struct stream *stream_deflate(struct stream *s, size_t len) {
+ struct stream *new = stream_new(len);
+ z_stream strm;
+ strm.zalloc = Z_NULL;
+ strm.zfree = Z_NULL;
+ strm.opaque = Z_NULL;
+
+ if (deflateInit(&strm, LEVEL) != Z_OK)
+ return NULL;
+
+ do {
+ strm.avail_in = len;
+ strm.next_in = (unsigned char *) s->_cur;
+ do {
+ strm.avail_out = len;
+ strm.next_out = (unsigned char *) new->_cur;
+ deflate(&strm, Z_NO_FLUSH); // Flush param may cause issues.
+ } while (strm.avail_out == 0);
+ } while (0);
+
+ deflateEnd(&strm);
+ return new;
+}