]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/compression/zlib/zlib.factor
factor: trim using lists
[factor.git] / basis / compression / zlib / zlib.factor
index a82352327d68374210d5c72e62a9670c2fd0ee20..0a3a15c1dea2dc4fb85fc114b6745f7fa078c66b 100644 (file)
@@ -1,10 +1,8 @@
 ! Copyright (C) 2009 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien alien.c-types alien.data alien.syntax
-byte-arrays byte-vectors classes.struct combinators
-compression.zlib.ffi continuations destructors fry kernel libc
-math math.functions math.ranges sequences system ;
-QUALIFIED: compression.zlib.ffi
+USING: accessors alien alien.c-types alien.data byte-vectors
+combinators compression.zlib.ffi continuations destructors
+kernel libc math math.functions ranges sequences ;
 IN: compression.zlib
 
 ERROR: zlib-failed n string ;
@@ -20,13 +18,13 @@ ERROR: zlib-failed n string ;
             "stream error" "data error"
             "memory error" "buffer error" "zlib version error"
         } ?nth
-    ] if throw-zlib-failed ;
+    ] if zlib-failed ;
 
 : zlib-error ( n -- )
     dup {
         { compression.zlib.ffi:Z_OK [ drop ] }
         { compression.zlib.ffi:Z_STREAM_END [ drop ] }
-        [ dup zlib-error-message throw-zlib-failed ]
+        [ dup zlib-error-message zlib-failed ]
     } case ;
 
 : compressed-size ( byte-array -- n )
@@ -38,7 +36,7 @@ ERROR: zlib-failed n string ;
         [ <byte-vector> dup underlying>> ] keep ulong <ref>
     ] keep [
         dup length compression.zlib.ffi:compress zlib-error
-    ] 2keep drop ulong deref >>length B{ } like ;
+    ] keepd ulong deref >>length B{ } like ;
 
 : (uncompress) ( length byte-array -- byte-array )
     [
@@ -49,20 +47,18 @@ ERROR: zlib-failed n string ;
     ] with-destructors ;
 
 : uncompress ( byte-array -- byte-array' )
-    [ length 5 [0,b) [ 2^ * ] with map ] keep
+    [ length 5 [0..b) [ 2^ * ] with map ] keep
     '[ _ (uncompress) ] attempt-all ;
 
 
 : zlib-inflate-init ( -- z_stream_s )
-    z_stream <struct> ZLIB_VERSION over byte-length [
-        inflateInit_ zlib-error
-    ] 3keep 2drop  ;
+    z_stream new
+    dup ZLIB_VERSION over byte-length inflateInit_ zlib-error ;
 
 ! window can be 0, 15, 32, 47 (others?)
 : zlib-inflate-init2 ( window -- z_stream_s )
-    [ z_stream <struct> ] dip ZLIB_VERSION pick byte-length [
-        inflateInit2_ zlib-error
-    ] 4keep 3drop  ;
+    [ z_stream new dup ] dip
+    ZLIB_VERSION pick byte-length inflateInit2_ zlib-error ;
 
 : zlib-inflate-end ( z_stream -- )
     inflateEnd zlib-error ;
@@ -74,6 +70,4 @@ ERROR: zlib-failed n string ;
     inflate zlib-error ;
 
 : zlib-inflate-get-header ( z_stream -- gz_header )
-    gz_header <struct> [
-        inflateGetHeader zlib-error
-    ] keep ;
+    gz_header new [ inflateGetHeader zlib-error ] keep ;