start deflation
parent
7e3501ad3f
commit
c44aafe1e5
@ -0,0 +1 @@
|
||||
#lang pitfall/racket
|
@ -0,0 +1,8 @@
|
||||
#lang pitfall/racket
|
||||
(require racket/draw/unsafe/png)
|
||||
|
||||
(define PNGImage
|
||||
(class object%
|
||||
(init-field data label)
|
||||
(field [image 'newPngobject]
|
||||
[width '()])))
|
@ -0,0 +1,30 @@
|
||||
#lang pitfall/racket
|
||||
(provide deflate inflate)
|
||||
|
||||
;; see https://groups.google.com/d/topic/racket-users/3CvjHLAmwSQ/discussion
|
||||
;; for discrepancies between gzip gunzip and zlib
|
||||
|
||||
(require (prefix-in gzip: file/gzip)
|
||||
(prefix-in gunzip: file/gunzip) png-image)
|
||||
|
||||
(define (deflate bstr)
|
||||
;; https://www.ietf.org/rfc/rfc1950.txt
|
||||
(define rfc-1950-header (bytes #x78 #x9c))
|
||||
(define op (open-output-bytes))
|
||||
(gzip:deflate (open-input-bytes bstr) op)
|
||||
(bytes-append rfc-1950-header
|
||||
(get-output-bytes op)
|
||||
(integer->integer-bytes (bytes-adler32 bstr) 4 #f 'want-big-endian)))
|
||||
|
||||
(define (inflate bstr)
|
||||
(define op (open-output-bytes))
|
||||
(gunzip:inflate (open-input-bytes (subbytes bstr 2)) op)
|
||||
(get-output-bytes op))
|
||||
|
||||
(module+ test
|
||||
(require rackunit)
|
||||
(for ([i (in-range 100)])
|
||||
(define random-bytes
|
||||
(apply bytes (for/list ([bidx (in-range 100)])
|
||||
(random 256))))
|
||||
(check-equal? random-bytes (inflate (deflate random-bytes)))))
|
Loading…
Reference in New Issue