Re: [racket-users] Re: inflate/deflate

2021-12-11 Thread Stephen De Gabrielle
On Fri, 10 Dec 2021 at 22:29, reilithion  wrote:

>
>
> On Friday, January 13, 2017 at 5:32:51 AM UTC-8 Tony Garnock-Jones wrote:
>
>> On 01/12/2017 11:32 PM, Lehi Toskin wrote:
>> > P.S. I didn't see an implementation of ADLER32 anywhere, so I had to
>> write my own, which took a little longer than expected, but oh well.
>>
>> Oh, cool. That'd probably be a useful thing for Racket's
>> net/git-checkout module, which has a piece of code in `zlib-inflate`
>> that reads:
>>
>> ...
>> (inflate i o)
>> ;; Verify checksum?
>> (read-bytes-exactly 'adler-checksum 4 i)
>> ...
>>
>> Perhaps you could contribute your adler32 implementation, and it could
>> be used there. (And perhaps that `zlib-inflate` function deserves being
>> pulled out into a separate module. Hmm.)
>>
>> Cheers,
>> Tony
>>
>
> Yes, please do this. I was in need of a zlib-inflate while working on a
> script to inspect Minecraft save data.
>

Please share!

S.



> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/853ecf97-23c9-4602-a0e1-038ddda3a0cdn%40googlegroups.com
> 
> .
>
-- 


-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAGHj7-%2BTrzx_-DBs1YxcZaC1tLH7wHALWFSuJNO2%2BN6aY8JaxQ%40mail.gmail.com.


Re: [racket-users] Re: inflate/deflate

2021-12-10 Thread reilithion


On Friday, January 13, 2017 at 5:32:51 AM UTC-8 Tony Garnock-Jones wrote:

> On 01/12/2017 11:32 PM, Lehi Toskin wrote: 
> > P.S. I didn't see an implementation of ADLER32 anywhere, so I had to 
> write my own, which took a little longer than expected, but oh well. 
>
> Oh, cool. That'd probably be a useful thing for Racket's 
> net/git-checkout module, which has a piece of code in `zlib-inflate` 
> that reads: 
>
> ... 
> (inflate i o) 
> ;; Verify checksum? 
> (read-bytes-exactly 'adler-checksum 4 i) 
> ... 
>
> Perhaps you could contribute your adler32 implementation, and it could 
> be used there. (And perhaps that `zlib-inflate` function deserves being 
> pulled out into a separate module. Hmm.) 
>
> Cheers, 
> Tony 
>

Yes, please do this. I was in need of a zlib-inflate while working on a 
script to inspect Minecraft save data. 

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/853ecf97-23c9-4602-a0e1-038ddda3a0cdn%40googlegroups.com.


Re: [racket-users] Re: inflate/deflate

2017-01-13 Thread Lehi Toskin
On Friday, January 13, 2017 at 5:32:51 AM UTC-8, Tony Garnock-Jones wrote:
> 
> Oh, cool. That'd probably be a useful thing for Racket's
> net/git-checkout module, which has a piece of code in `zlib-inflate`
> that reads:
> 
>   ...
>   (inflate i o)
>   ;; Verify checksum?
>   (read-bytes-exactly 'adler-checksum 4 i)
>   ...
> 
> Perhaps you could contribute your adler32 implementation, and it could
> be used there. (And perhaps that `zlib-inflate` function deserves being
> pulled out into a separate module. Hmm.)
> 
> Cheers,
>   Tony

Sounds good to me! I just made a PR.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: inflate/deflate

2017-01-13 Thread Tony Garnock-Jones
On 01/12/2017 11:32 PM, Lehi Toskin wrote:
> `number->bytes`, is a function I made; its definition is
> (define (number->bytes num)
>   (define hex (number->string num 16))
>   ; from file/sha1
>   (hex-string->bytes (if (even? (string-length hex)) hex (string-append "0" 
> hex

You might be able to use Racket's built-in `integer->integer-bytes`
here:
http://docs.racket-lang.org/reference/generic-numbers.html?q=integer%20bytes#%28def._%28%28quote._~23~25kernel%29._integer-~3einteger-bytes%29%29

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: inflate/deflate

2017-01-13 Thread Tony Garnock-Jones
On 01/12/2017 11:32 PM, Lehi Toskin wrote:
> P.S. I didn't see an implementation of ADLER32 anywhere, so I had to write my 
> own, which took a little longer than expected, but oh well.

Oh, cool. That'd probably be a useful thing for Racket's
net/git-checkout module, which has a piece of code in `zlib-inflate`
that reads:

  ...
  (inflate i o)
  ;; Verify checksum?
  (read-bytes-exactly 'adler-checksum 4 i)
  ...

Perhaps you could contribute your adler32 implementation, and it could
be used there. (And perhaps that `zlib-inflate` function deserves being
pulled out into a separate module. Hmm.)

Cheers,
  Tony

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: inflate/deflate

2017-01-12 Thread Lehi Toskin
Thanks to Tonyg's links, I figured out that the part I was missing was the 
ADLER-32 check of the uncompressed data added to the end of the byte string.

That makes the total byte string composition look like this:
(bytes #x78 #x9c) compressed-data-from-deflate (number->bytes (adler32 
uncompressed-text))

`number->bytes`, is a function I made; its definition is
(define (number->bytes num)
  (define hex (number->string num 16))
  ; from file/sha1
  (hex-string->bytes (if (even? (string-length hex)) hex (string-append "0" 
hex

P.S. I didn't see an implementation of ADLER32 anywhere, so I had to write my 
own, which took a little longer than expected, but oh well.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: inflate/deflate

2017-01-12 Thread Tony Garnock-Jones
Hi Lehi,

On 01/12/2017 06:17 PM, Lehi Toskin wrote:
> Now that I think about it, it's probably naive of
> me to simple add those two bytes and expect everything to actually be
> working as expected [...] I'm assuming the Z_BUF_ERROR is being
> reported because it's not as flexible and the structure of the data
> is missing some information like length (or something).

See FAQs 18 and 19 here: http://www.gzip.org/zlib/zlib_faq.html#faq18

and see also RFC 1950, that explains why the bytes you need are 0x789c,
and explains the kind of trailer you should probably also have:
https://www.ietf.org/rfc/rfc1950.txt

I wonder if the Z_BUF_ERROR is related to a missing checksum trailer.

(I remember running into this a couple of years ago. I've forgotten the
details, but the gist of it is that the DEFLATE format is the underlying
compression method, and that it can be placed in either a zlib envelope
(RFC 1950) or a gzip envelope (separately specified, probably not what
you want here).)

Tony

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.