解碼:gzip壓縮數據後再base64編碼的數據流

(in-package :cl-user)
;樣例數據
(defvar str
"H4sIAAAAAAAAAE2STUvDQBCG/0puOdXdpIGkMG7ZJtMabDdhsxU85aBFCtqCgviTPHlQKPhxEEFB
Lx69+AsELx49iLvdfPSyPO/MO7szw0L/4uTYOZ+dns2Xi23X26KuM1scLA/niyNn23FHg123zyCb
KgY7yBOUDJTkooyzBJlHQx9Iq2E4FUmZJsyPoi6QWoHEPJOqVPs5MuoB2dSQikLZckpNstVQoEz5
uBQZ8yIa0EC/F/S63R6QNgMJ5pU/pF4EpNUwwFEqyoQrZD61VwDZCALqBi2RFmPUvZmbSUMShzbS
QL2MOBMKhd6OLPJqCj15I4DHsSnQrekOfF+PSH0vDLWnylgHnyB7unn9Wv3dPa8u338+3q5/bz8f
vx9e7q8qq7GszfFUv0saMlAoO8QGG+RK1VaLhgZ8XMXWpI9SpRO7oQ4NOusd1UHge7yuaKiZmZh/
8Q+1v/5CQwIAAA==")


;取當前目錄
(defun getcurdir nil
(multiple-value-bind (len dir) (WIN32:GetCurrentDirectoryA 260)
(string-concat dir "\\")))

(defparameter *gzip-path* (string-concat (getcurdir) "gzip.exe"))

;解壓 gzip字符流
(defun get-unzip-text nil
(let ((out (make-pipe-output-stream (string-concat *gzip-path* " " "-c -d") :element-type '(unsigned-byte 8))))
(unwind-protect
(write-byte-sequence 
(convert-string-to-bytes (clipboard) charset:base64)
out)
(close out))))

;解碼 gzip編碼的字節流
;調用命令:gzip -c -d file
(defun get-unzip-text nil
(let ((*gzip-path* (string-concat (getcurdir) "gzip.exe")));重設當前gzip路徑
(multiple-value-bind (io in out) (make-pipe-io-stream (string-concat *gzip-path* " " "-c -d") :element-type '(unsigned-byte 8))
(unwind-protect
(progn
(write-byte-sequence 
(convert-string-to-bytes (clipboard) charset:base64)
io)
(close out)
(convert-string-from-bytes 
(coerce 
(loop for x = (read-byte io nil) while x collect x) 
'vector)
charset:gbk))
(close io)))))

;測試
(defun test-1 nil
(setf (clipboard) str)
(get-unzip-text))
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章