分类号:TP301.6 U D C:D10621-408-(2007)5925-0
密 级:公 开 编 号:2003031194
成 都 信 息 工 程 学 院
学 位 论 文
文件压缩与解压缩实践
论 文 作 者 姓 名 :
袁渊
申 请 学 位 专 业 :
计算机科学与技术
申 请 学 位 类 别 :
工学学士
指导教师姓名(职称):
叶安胜(讲师)
论 文 提 交 日 期 :
2007 年 6 月 10 日
文件压缩与解压缩实践
摘 要
随着人们对数据的大量需求以及计算机使用时间的增加,计算机磁盘上的文
件越来越大,越来越多。如何让有限的磁盘空间容纳更多的数据成为需要解决的
问题。一方面,高速发展的存储技术以提高磁盘容量来解决这样的需求,但随着
网络环境下数据传递的产生以及带宽的限制,大容量数据问题日益突出。在这两
种需求的推动下,对数据压缩的需求产生了。人们可以将文件在不改变其本身的
条件下,将其以更小的占用空间存储,并且在需要的时候将文件恢复成原有的样
子,这就是压缩目的。本论文主要研究文件的无损压缩技术,并简要介绍了文件
压缩的分类、几种常用的无损压缩格式和常用的压缩算法。运用 LZ77 字典算法、
懒惰匹配算法和 Huffman 编码算法,使用 Java 语言在 Jbuilder2006 环境下设计了
使用 GZIP 算法对文件压缩与解压缩的实现程序。用户可以根据自己的需求,使
用此程序方便地对文件进行压缩或者解压缩操作。
关键词:压缩;解压缩;GZIP;Java
Practice of File Compression and Decompression
Abstract
As the great demand for data and the using time of computer are increasing,
computer files on the disk grow more and more. How to make the limited disk space
to store more data has became a problem crying out for solutions. On one hand, the
rapid development of storage technology that can increase the disk capacity, can meet
such demand. However, with the emergence of data transmission in a network
environment and the bandwidth limitations, the problem of large-capacity data is
increasingly prominent. With the promotion of both demands, the need for data
compression and decompression is generated. People can store a file with a smaller
storage space without changing the file’s own condition, and can restore the file; that
is the purpose of data compression and decompression. This treatise principally
research file lossless compression, otherwise, briefly introduced classification of file
compression, some general lossless compression format and general compression
algorithm. A procedure within algorithm called GZIP were designed for file
compression and decompression in Java language under the circumstances of
Jbuilder2006,which used LZ77 dictionary algorithm, lazy match algorithm and
Huffman coding algorithm. Users could use this procedure compress or decompress
files expediently according to their demand.
Key words: Compression; Decompression; GZIP; Java
目 录
论文总页数:21 页
1 引言............................................................................................................................................1
1.1 课题背景 ..........................................................................................................................1
1.2 国内外现有的研究成果 ..................................................................................................1
2 压缩与解压缩程序分析............................................................................................................2
2.1 需求分析 ..........................................................................................................................2
2.2 使用的算法理论 ..............................................................................................................2
2.2.1 LZ77 算法简介..........................................................................................................2
2.2.2 Huffman 算法简介 ....................................................................................................3
2.2.3 GZIP 算法原理分析..................................................................................................4
2.3 开发环境 ..........................................................................................................................4
3 总体设计....................................................................................................................................4
3.1 程序功能模块 ..................................................................................................................5
3.2 模块分析与流程图 ..........................................................................................................5
3.2.1 压缩模块....................................................................................................................5
3.2.2 解压缩模块................................................................................................................6
3.3 程序中各个类的初步定义 ..............................................................................................7
4 详细设计和实现........................................................................................................................8
4.1 压缩的程序流程 ..............................................................................................................8
4.2 解压缩的程序流程 ..........................................................................................................9
4.3 主函数代码 ....................................................................................................................10
4.3.1 gzip 压缩模块代码..................................................................................................10
4.3.2 ungzip 解压缩模块代码..........................................................................................11
4.4 程序界面设计 ................................................................................................................12
5 软件系统测试..........................................................................................................................17
5.1 运行环境 ........................................................................................................................17
5.2 测试方法 ........................................................................................................................17
5.3 测试结果 ........................................................................................................................17
5.3.1 使用程序对 txt 文件压缩 .......................................................................................17
5.3.2 使用程序对 bmp 图象文件压缩.............................................................................18
5.3.3 使用程序对 doc 文件压缩......................................................................................18
结 论..............................................................................................................................................18
参考文献..........................................................................................................................................19
致 谢..........................................................................................................................................20