Re: streams, reading bytes

2013-10-11 Thread Zach Tellman
The byte-transforms library will also take care of the gzip stuff for 
you: https://github.com/ztellman/byte-transforms

On Thursday, October 10, 2013 10:26:35 PM UTC-4, Brian Craft wrote:

 I like the blurb:

 This library is a Rosetta stone for all the byte representations Java has 
 to offer, and gives you the freedom to forget all the APIs you never wanted 
 to know in the first place.

 My feelings, exactly. ;)

 Thanks.

 On Thursday, October 10, 2013 6:44:32 PM UTC-7, Ben Mabey wrote:

 On 10/10/13 7:21 PM, Brian Craft wrote: 
  I'm struggling with how to gzip/gunzip byte arrays from clojure. I 
  don't really get how clojure.java.io streams supposed to be used. 
  
  This appears to gzip a string: 
  
  (let [baos (java.io.ByteArrayOutputStream.) 
gzos (java.util.zip.GZIPOutputStream. baos)] 
  (.write gzos (.getBytes foo)) 
  (.finish gzos) 
  (.toByteArray baos)) 
  
  
  and I can expand on this to gunzip the string afterwards: 
  
  (let [baos (java.io.ByteArrayOutputStream.) 
gzos (java.util.zip.GZIPOutputStream. baos)] 
(.write gzos (.getBytes foo)) 
(.finish gzos) 
(let [gzbytes (.toByteArray baos) 
  bais (java.io.ByteArrayInputStream. gzbytes) 
  gzis (java.util.zip.GZIPInputStream. bais)] 
  (slurp gzis))) 
  
  But slurp builds strings. I need to do this with byte arrays.  Do I 
  have to rewrite slurp to build a byte array? Is there any simpler way 
  to do this? 

 Zach Tellman's byte-streams library is very handy for these kinds of 
 conversions: 

 https://github.com/ztellman/byte-streams 

 -Ben 



-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: streams, reading bytes

2013-10-10 Thread Brian Craft
I like the blurb:

This library is a Rosetta stone for all the byte representations Java has 
to offer, and gives you the freedom to forget all the APIs you never wanted 
to know in the first place.

My feelings, exactly. ;)

Thanks.

On Thursday, October 10, 2013 6:44:32 PM UTC-7, Ben Mabey wrote:

 On 10/10/13 7:21 PM, Brian Craft wrote: 
  I'm struggling with how to gzip/gunzip byte arrays from clojure. I 
  don't really get how clojure.java.io streams supposed to be used. 
  
  This appears to gzip a string: 
  
  (let [baos (java.io.ByteArrayOutputStream.) 
gzos (java.util.zip.GZIPOutputStream. baos)] 
  (.write gzos (.getBytes foo)) 
  (.finish gzos) 
  (.toByteArray baos)) 
  
  
  and I can expand on this to gunzip the string afterwards: 
  
  (let [baos (java.io.ByteArrayOutputStream.) 
gzos (java.util.zip.GZIPOutputStream. baos)] 
(.write gzos (.getBytes foo)) 
(.finish gzos) 
(let [gzbytes (.toByteArray baos) 
  bais (java.io.ByteArrayInputStream. gzbytes) 
  gzis (java.util.zip.GZIPInputStream. bais)] 
  (slurp gzis))) 
  
  But slurp builds strings. I need to do this with byte arrays.  Do I 
  have to rewrite slurp to build a byte array? Is there any simpler way 
  to do this? 

 Zach Tellman's byte-streams library is very handy for these kinds of 
 conversions: 

 https://github.com/ztellman/byte-streams 

 -Ben 



-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.