2010-11-17 30 views
2

我可以打開一個zip條目並調整內容,但我無法弄清楚如何保存它們。如何在Common Lisp中寫入壓縮文件?

CL ZIP的API想要。

規格:

ZIP

Quicklisp

MacPorts的CLISP 2.49

Aquamacs 2.1(Emacs的23.2)

的Mac OS X 10.6.4

的MacBook Pro 5 ,1

; Removes newlines at the beginning of PRE tags in Sigil-edited ePub files. 
; 
; See http://code.google.com/p/sigil/issues/detail?id=655 
; 
; Andrew Pennebaker 
; 16 Nov 2010 

; Requires Quicklisp. 
; http://www.quicklisp.org/ 
(ql:quickload "zip") 
(ql:quickload "cl-ppcre") 

(defvar *epub* nil) 
(defvar *epub-contents* nil) 
(defvar *epub-out* nil) 

(defun load-epub (filename) 
    (setq *epub* (zip:open-zipfile filename))) 

(defun close-epub() 
    (zip:close-zipfile *epub*) 
    (setq *epub* nil) 
    (setq *epub-contents* nil)) 

(defun gather-epub-contents() 
    (zip:do-zipfile-entries (name entry *epub*) 
     (push name *epub-contents*))) 

(defun is-html-file (name) 
    (if (cl-ppcre:scan ".+\\.htm[l]?$" name) t nil)) 

(defun entry-name-to-html (name) 
    (flexi-streams:octets-to-string 
    (zip:zipfile-entry-contents 
    (zip:get-zipfile-entry name *epub*)))) 

(defun clean (html) 
    (values 
    (cl-ppcre:regex-replace-all 
    "<pre[^>]*>(\\s)*" 
    (cl-ppcre:regex-replace-all "\\s+</pre>" html "</pre>") 
    "<pre>"))) 

回答

0

根據Common Lisp ZIP庫的文檔,您必須獲得一個單獨的句柄才能寫入zip文件。可能你可以將內容提取到一個文件夾,調整內容並通過一次調用來壓縮整個文件夾(zip path-name source-folder)

+0

相當。但是,我怎樣才能讀取一個zip文件並寫入另一個zip文件(或者更好,寫入第一個zip文件)? – mcandre 2010-11-18 05:05:02