From: Ken A. <kan...@bb...> - 2003-12-04 22:17:59
|
Here's some code for reading and writing data from a zipped file. It assumes the zipped file has only one element, the file you want to read. I though Geoffrey might like this, but Rusty would say "wait a year and space will be twice as cheap". k (import "java.util.zip.ZipFile") (import "java.util.zip.ZipOutputStream") (import "java.util.zip.ZipEntry") ;;; withZipWriter: String File (PrintWriter -> void) -> void (define (withZipWriter name outputFile f) ;; outputFile will be a zip file with one element in it, named name. (let* ((out (ZipOutputStream. (FileOutputStream. outputFile))) (w (PrintWriter. (BufferedWriter. (OutputStreamWriter. out))))) (.putNextEntry out (ZipEntry. name)) (f w) (.flush w) (.closeEntry out) (.close out))) ;;; withZipReader: ZipFile (BufferedReader -> Object) -> Object (define (withZipReader zipFile f) (let* ((zip (ZipFile. zipFile)) (r (BufferedReader. (InputStreamReader. (.getInputStream zip (.nextElement (.entries zip)))))) (result (f r))) (.close r) result)) |