解码: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))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值