source: project/release/4/lzma/trunk/lzma.scm @ 15236

Last change on this file since 15236 was 15236, checked in by Alaric Snell-Pym, 11 years ago

Egg 3 brought up

File size: 1.2 KB
Line 
1(declare (export lzma:compress lzma:decompress))
2
3(use lolevel)
4
5(foreign-declare "#include <lzmalib.h>")
6
7(foreign-declare "static int lzma_return_buffer_len;")
8
9(define-foreign-variable lzma-return-buffer-len int "lzma_return_buffer_len")
10(define _decompress (foreign-lambda* c-pointer ((blob inblob) (int inlen))
11   "C_return (lzma_decompress(inblob, inlen, &lzma_return_buffer_len));"))
12(define _compress (foreign-lambda* c-pointer ((blob inblob) (int inlen))
13   "C_return (lzma_compress(inblob, inlen, &lzma_return_buffer_len));"))
14(define _free (foreign-lambda void "lzma_free" c-pointer))
15
16(define (lzma:decompress inblob)
17   (let ((ptr (_decompress inblob (blob-size inblob))))
18      (if (null-pointer? ptr)
19         #f
20         (let ((outblob (make-blob lzma-return-buffer-len)))
21            (begin
22               (move-memory! ptr outblob lzma-return-buffer-len)
23               (_free ptr)
24               outblob)))))
25
26(define (lzma:compress inblob)
27   (let ((ptr (_compress inblob (blob-size inblob))))
28      (if (null-pointer? ptr)
29         #f
30         (let ((outblob (make-blob lzma-return-buffer-len)))
31            (begin
32               (move-memory! ptr outblob lzma-return-buffer-len)
33               (_free ptr)
34               outblob)))))
Note: See TracBrowser for help on using the repository browser.