# LZ77
## Dependencies
- Pyhton3
- bitarray
> Get bitarray module on Windows platform: https://www.lfd.uci.edu/~gohlke/pythonlibs/#bitarray
> Bitarray API: https://pypi.python.org/pypi/bitarray/
## Some Definition
- input stream: The sequence of bytes to be compressed.
- coding position: The position of the byte in the input stream that is currently being coded (the beginning of the lookahead buffer).
- lookahead buffer: The byte sequence from the coding position to the end of the input stream.
- window: A buffer of size W that indicates the number of bytes from the coding position backward. The window is empty at the beginning of the compression, then grows to size W as the input stream is processed.Once it reaches size W, it then "slides" along with the coding position
> 术语定义来自 MSDN: https://msdn.microsoft.com/en-us/library/ee916854.aspx
## Simple Test Example
![test1](https://s1.ax1x.com/2018/02/26/90s3Kx.png)
First type `python3 LZ77.py` in the shell, and then it will ask you as this:
Press 1 for compress or 2 for decompress:
you should make a choice and here take 1 for example. Then input the file's path according to the promot infomation. Here the test file's path is `/home/lv/LZ77/test.txt`, which is in UTF-8 encoding. The file content is a string `ABCD?ABCDabcabcabcabcabcabc`. In test mode, it will print the compression description. In this example, it will print:
<0, A> <0, B> <0, C> <0, D> <0, ?> <1, 5, 4> <0, a> <0, b> <0, c> <1, 3, 15>
## Usage
```python
form LZ77 import LZ77Compressor
compressor = LZ77Compressor(window_size=4096, lookahead_buffer_size=32)
```
- `window_size` and `lookahead_buffer_size` are optional, and their default value are 4096 and 32, which means that the window's size is 4096 bytes and lookahead-buffer's size is 32 bytes.
In defalut mode, the structure of a phrase token and a symbol token are:
![struction](https://s1.ax1x.com/2018/02/26/90ctaT.jpg)
### compress function
compressor.compress(input_file_path[, output_file_path, get_data, display]):
- `output_file_path`, `get_data` and `display` are optional;
- when `output_file_path` is not given, it will creat `input_file_path.LZ77` as compressed file. Take `input_file_path='/home/lv/test.txt'` for example, the output file is '/home/lv/test.txt.LZ77';
- `get_data` is `False` in default, when enable `get_data`, the compress function will return a **bitarray**;
- `display` is `False` in default, when `display` is `True` and the size of input file is less than 513 bytes, the compression description is printed to standard output.
### decompress function
compressor.decompress(input_file_path[, output_file_path, get_data])
- `output_file_path` and `get_data` are optional;
- when `output_file_path` is not given, it will creat `input_file_path.LZ77dec` as compressed file. Take `input_file_path='/home/lv/test.txt.LZ77'` for example, the output file is '/home/lv/test.txt.LZ77.dec';
- `get_data` is `False` in default, when enable `get_data`, the compress function will return a **bytearray**;
> **for more information, please read LZ77.py.**
没有合适的资源?快使用搜索试试~ 我知道了~
基于霍夫曼编码、费诺编码、霍夫曼压缩、LZ77压缩C仿真源码.zip
共28个文件
cpp:8个
txt:5个
h:5个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 63 浏览量
2023-10-17
16:23:22
上传
评论
收藏 46KB ZIP 举报
温馨提示
基于霍夫曼编码、费诺编码、霍夫曼压缩、LZ77压缩C仿真源码.zip 代码完整下载可用,确保可以运行。 基于霍夫曼编码、费诺编码、霍夫曼压缩、LZ77压缩C仿真源码.zip 代码完整下载可用,确保可以运行。基于霍夫曼编码、费诺编码、霍夫曼压缩、LZ77压缩C仿真源码.zip 代码完整下载可用,确保可以运行。基于霍夫曼编码、费诺编码、霍夫曼压缩、LZ77压缩C仿真源码.zip 代码完整下载可用,确保可以运行。基于霍夫曼编码、费诺编码、霍夫曼压缩、LZ77压缩C仿真源码.zip 代码完整下载可用,确保可以运行。基于霍夫曼编码、费诺编码、霍夫曼压缩、LZ77压缩C仿真源码.zip 代码完整下载可用,确保可以运行。基于霍夫曼编码、费诺编码、霍夫曼压缩、LZ77压缩C仿真源码.zip 代码完整下载可用,确保可以运行。基于霍夫曼编码、费诺编码、霍夫曼压缩、LZ77压缩C仿真源码.zip 代码完整下载可用,确保可以运行。基于霍夫曼编码、费诺编码、霍夫曼压缩、LZ77压缩C仿真源码.zip 代码完整下载可用,确保可以运行。基于霍夫曼编码、费诺编码、霍夫曼压缩、LZ77压缩C仿真源码.zip 代码完
资源推荐
资源详情
资源评论
收起资源包目录
基于霍夫曼编码、费诺编码、霍夫曼压缩、LZ77压缩C仿真.zip (28个子文件)
基于霍夫曼编码、费诺编码、霍夫曼压缩、LZ77压缩C仿真
huffman_Compress
src
huffman.cpp 11KB
main.cpp 192B
bitstream.cpp 3KB
huffman_ui.cpp 10KB
header
bitstream.h 964B
huffman_ui.h 137B
huffman.h 5KB
LZ77
LZ77.py 11KB
test.txt.LZ77 14B
forked_from_manassra
LICENSE 1KB
LZ77.py 5KB
examples
input.txt 231B
decompressed.txt 231B
compressed_window_100.txt 71B
requirements.txt 16B
README.md 2KB
test.txt 27B
test.txt.LZ77.LZ77dec 27B
README.md 3KB
.gitattributes 2KB
Huffman_C++
huffman.cpp 7KB
main.cpp 221B
huffman_ui.h 157B
huffman_ui.cpp 6KB
huffman.h 3KB
fano
fano.cpp 6KB
Huffman_C
HuffmanCode.c 5KB
.gitignore 4KB
共 28 条
- 1
资源评论
- SA1111111112023-12-27资源内容详细,总结地很全面,与描述的内容一致,对我启发很大,学习了。
不安分的小女孩
- 粉丝: 9200
- 资源: 1990
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功