python使用装饰器实现图种功能

· Special

引用个概念:

图种是一种利用图片文件来传递压缩包的技巧。图种以图像浏览器开启时,就是一张单纯的图片。但可以以压缩软件对其解压缩,获取附加在图片档后的压缩包内容。

例子

The.Secret.Life.Of.Walter.Mitty

原理

代码实现

#函数读取两个文件路径并相加

#使用闭包函数获取名称
def twice_process(old_func):
    def inner(*args, **kwargs):
        res = old_func(**kwargs)
        with open(f'{args[0]}.png','wb') as f:
            f.write(res)

    return inner

@twice_process
def plus_process(pic_path,zip_path):
    with open(pic_path,'rb') as f:
        pic_bin = f.read()

    with open(zip_path,'rb') as f1:
        zip_bin = f1.read()

    all_bin = pic_bin+zip_bin
    return all_bin



#接受用户输入的名称
input_user_input = input('enter your file_name: ')
input_pic_path = input('enter your pic path: ')
input_zip_path = input('enter your zip file path: ')
plus_process(f'{input_user_input}',pic_path=f"{input_pic_path}",zip_path=f"{input_zip_path}")

python


评论