CN106936441B - A data compression method and device - Google Patents
A data compression method and device Download PDFInfo
- Publication number
- CN106936441B CN106936441B CN201710108980.0A CN201710108980A CN106936441B CN 106936441 B CN106936441 B CN 106936441B CN 201710108980 A CN201710108980 A CN 201710108980A CN 106936441 B CN106936441 B CN 106936441B
- Authority
- CN
- China
- Prior art keywords
- data
- compressed
- length
- compression algorithm
- compression
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 66
- 238000013144 data compression Methods 0.000 title claims abstract description 37
- 238000007906 compression Methods 0.000 claims abstract description 134
- 230000006835 compression Effects 0.000 claims abstract description 134
- 230000006837 decompression Effects 0.000 claims abstract description 38
- 125000004122 cyclic group Chemical group 0.000 claims description 26
- 238000012795 verification Methods 0.000 claims description 22
- 230000009286 beneficial effect Effects 0.000 abstract description 3
- 230000005540 biological transmission Effects 0.000 description 3
- 230000008878 coupling Effects 0.000 description 3
- 238000010168 coupling process Methods 0.000 description 3
- 238000005859 coupling reaction Methods 0.000 description 3
- 238000010586 diagram Methods 0.000 description 3
- 230000008569 process Effects 0.000 description 3
- 238000004891 communication Methods 0.000 description 2
- 238000005457 optimization Methods 0.000 description 2
- 238000012545 processing Methods 0.000 description 2
- 238000012669 compression test Methods 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 230000006870 function Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 238000012360 testing method Methods 0.000 description 1
- 230000001960 triggered effect Effects 0.000 description 1
Images
Classifications
-
- H—ELECTRICITY
- H03—ELECTRONIC CIRCUITRY
- H03M—CODING; DECODING; CODE CONVERSION IN GENERAL
- H03M7/00—Conversion of a code where information is represented by a given sequence or number of digits to a code where the same, similar or subset of information is represented by a different sequence or number of digits
- H03M7/30—Compression; Expansion; Suppression of unnecessary data, e.g. redundancy reduction
- H03M7/60—General implementation details not specific to a particular type of compression
- H03M7/6064—Selection of Compressor
- H03M7/6082—Selection strategies
- H03M7/6088—Selection strategies according to the data type
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
- Compression, Expansion, Code Conversion, And Decoders (AREA)
Abstract
本发明提供了一种数据压缩方法包括:接收数据压缩请求,获取需要压缩的数据以及压缩所述数据所选择的压缩算法;根据所选择的压缩算法对需要压缩的数据进行压缩,得到压缩后的数据;将所述压缩算法对应的标识添加到包头的第一指定位置,由所述压缩后的数据和包头生成压缩数据包。通过压缩算法的标识的设定,可以使得本方法能够适应不同的算法的压缩文件的解压和压缩,有利于提高用户使用的便利性。
The invention provides a data compression method comprising: receiving a data compression request, obtaining data to be compressed and a compression algorithm selected for compressing the data; compressing the data to be compressed according to the selected compression algorithm, and obtaining a compressed data data; adding the identifier corresponding to the compression algorithm to the first designated position of the packet header, and generating a compressed data packet from the compressed data and the packet header. By setting the identifier of the compression algorithm, the method can be adapted to the decompression and compression of compressed files of different algorithms, which is beneficial to improve the convenience of the user.
Description
技术领域technical field
本发明属于数据压缩领域,尤其涉及一种数据压缩方法和装置。The invention belongs to the field of data compression, and in particular relates to a data compression method and device.
背景技术Background technique
数据压缩是指在不丢失有用信息的前提下,按照一定的算法对数据进行重新组织,减少数据的冗余和存储的空间,提高其传输、存储和处理效率的方法。通过数据压缩算法将需要存储、传送的数据进行压缩后,可以使用较小的存储空间存储更多的数据,并且在数据传输时,能够大大的节约网络资源,并且提高传输的效率。Data compression refers to a method of reorganizing data according to a certain algorithm, reducing data redundancy and storage space, and improving its transmission, storage and processing efficiency without losing useful information. After the data that needs to be stored and transmitted is compressed by the data compression algorithm, a smaller storage space can be used to store more data, and during data transmission, network resources can be greatly saved, and the transmission efficiency can be improved.
目前,对数据进行压缩时,通常是选用现有的数据压缩工具,比如WINRAR、WINZIP、好压、360压缩等工具。并且不同的压缩工具所采用的压缩算法也可能不相同。因此,当用户使用压缩工具A进行压缩时,在不同的使用环境中,比如将压缩的数据发送至其它用户,或者将压缩的数据复制到其它设备中时,可能会由于压缩工具的不同,无法对数据进行有效的解压。需要用户在新的设备中安装对应的压缩工具,操作较为麻烦。At present, when compressing data, existing data compression tools are usually used, such as WINRAR, WINZIP, HaoPress, 360 compression and other tools. And the compression algorithms used by different compression tools may also be different. Therefore, when a user uses compression tool A to compress, in different usage environments, such as sending compressed data to other users or copying compressed data to other devices, it may not be possible due to different compression tools. Efficient decompression of data. The user needs to install the corresponding compression tool in the new device, which is troublesome to operate.
发明内容SUMMARY OF THE INVENTION
本发明的目的在于提供一种数据压缩方法和装置,以解决现有技术由于压缩工具多种多样,导致压缩的数据不能有效的适应不同的工具进行解压,用户操作不方便的问题。The purpose of the present invention is to provide a data compression method and device to solve the problem that the compressed data cannot be effectively adapted to different tools for decompression due to the variety of compression tools in the prior art, and the user's operation is inconvenient.
第一方面,本发明实施例提供了一种数据压缩方法,所述方法包括:In a first aspect, an embodiment of the present invention provides a data compression method, the method comprising:
接收数据压缩请求,获取需要压缩的数据以及压缩所述数据所选择的压缩算法;Receive a data compression request, obtain the data to be compressed and the compression algorithm selected for compressing the data;
根据所选择的压缩算法对需要压缩的数据进行压缩,得到压缩后的数据;Compress the data to be compressed according to the selected compression algorithm to obtain the compressed data;
将所述压缩算法对应的标识添加到包头的第一指定位置,由所述压缩后的数据和包头生成压缩数据包。The identifier corresponding to the compression algorithm is added to the first designated position of the packet header, and a compressed data packet is generated from the compressed data and the packet header.
结合第一方面,在第一方面的第一种可能实现方式中,在所述接收数据压缩请求,获取需要压缩的数据以及选择压缩所述数据所选择的压缩算法的步骤之后,所述方法还包括:With reference to the first aspect, in a first possible implementation manner of the first aspect, after the steps of receiving a data compression request, acquiring data to be compressed, and selecting a compression algorithm selected for compressing the data, the method further include:
对需要压缩的数据进行循环冗余校验,生成循环冗余校验结果;Perform a cyclic redundancy check on the data to be compressed to generate a cyclic redundancy check result;
将所述循环冗余校验结果添加到所述包头的第二指定位置。The CRC result is added to the second specified position of the packet header.
结合第一方面,在第一方面的第二种可能实现方式中,在所述接收数据压缩请求,获取需要压缩的数据以及选择压缩所述数据所选择的压缩算法的步骤之后,所述方法还包括:With reference to the first aspect, in a second possible implementation manner of the first aspect, after the steps of receiving a data compression request, acquiring data to be compressed, and selecting a compression algorithm selected for compressing the data, the method further include:
获取压缩后的数据的长度以及需要压缩的数据的原始长度;Get the length of the compressed data and the original length of the data to be compressed;
将所述压缩后的数据的长度写入所述包头的第三指定位置,以及将需要压缩的数据的原始长度写入包头的第四指定位置。The length of the compressed data is written into the third specified position of the packet header, and the original length of the data to be compressed is written into the fourth specified position of the packet header.
第二方面,本发明实施例提供了一种数据解压方法,所述方法包括:In a second aspect, an embodiment of the present invention provides a data decompression method, the method comprising:
接收数据解压请求,获取压缩数据包中的压缩后的数据所对应的压缩算法对应的标识,以及在压缩数据包的指定位置获取压缩后的数据;Receive the data decompression request, obtain the identifier corresponding to the compression algorithm corresponding to the compressed data in the compressed data packet, and obtain the compressed data at the designated position of the compressed data packet;
根据所述标识查找对应的压缩算法,根据所述压缩算法对压缩后的数据进行解压缩,得到解压缩的数据。The corresponding compression algorithm is searched according to the identifier, and the compressed data is decompressed according to the compression algorithm to obtain decompressed data.
结合第二方面,在第二方面的第一种可能实现方式中,在所述根据所述标识查找对应的压缩算法,根据所述压缩算法对压缩后的数据进行解压缩,得到解压缩的数据步骤之后,所述方法还包括:With reference to the second aspect, in a first possible implementation manner of the second aspect, in the searching for a corresponding compression algorithm according to the identifier, the compressed data is decompressed according to the compression algorithm to obtain decompressed data After the step, the method further includes:
通过循环结果校验方法对解压的数据进行校验,生成解压数据的校验结果;The decompressed data is verified by the cyclic result verification method, and the verification result of the decompressed data is generated;
将所述解压数据的校验结果与存储在包头第二指定位置的校验结果进行比较,根据比较结果判断所述解压的数据的完整性。The verification result of the decompressed data is compared with the verification result stored in the second designated position of the packet header, and the integrity of the decompressed data is judged according to the comparison result.
结合第二方面,在第二方面的第二种可能实现方式中,在所述根据所述标识查找对应的压缩算法,根据所述压缩算法对压缩后的数据进行解压缩,得到解压缩的数据步骤之前,所述方法还包括:With reference to the second aspect, in a second possible implementation manner of the second aspect, in the searching for a corresponding compression algorithm according to the identifier, the compressed data is decompressed according to the compression algorithm to obtain decompressed data Before the step, the method further includes:
获取包头的第三指定位置中存储的压缩后的数据的长度,以及所述压缩数据包中的压缩后的数据的长度,根据压缩后的数据的长度与存储的长度的比较结果判断数据是否完整;Obtain the length of the compressed data stored in the third designated position of the packet header, and the length of the compressed data in the compressed data packet, and judge whether the data is complete according to the comparison result of the length of the compressed data and the stored length ;
以及在所述根据所述标识查找对应的压缩算法,根据所述压缩算法对压缩后的数据进行解压缩,得到解压缩的数据步骤之后,所述方法还包括:And after the step of searching for a corresponding compression algorithm according to the identifier, decompressing the compressed data according to the compression algorithm, and obtaining decompressed data, the method further includes:
获取包头的第四指定位置存储的压缩前的数据的长度,以及解压缩的数据的长度,根据解压缩的数据的长度与存储的长度的比较结果判断解压后的数据是否完整。Obtain the length of the data before compression and the length of the decompressed data stored in the fourth designated position of the packet header, and determine whether the decompressed data is complete according to the comparison result between the length of the decompressed data and the stored length.
第三方面,本发明实施例提供了一种数据压缩装置,所述装置包括:In a third aspect, an embodiment of the present invention provides a data compression apparatus, the apparatus comprising:
请求单元,用于接收数据压缩请求,获取需要压缩的数据以及压缩所述数据所选择的压缩算法;a request unit, configured to receive a data compression request, obtain data to be compressed and a compression algorithm selected for compressing the data;
压缩单元,用于根据所选择的压缩算法对需要压缩的数据进行压缩,得到压缩后的数据;The compression unit is used for compressing the data to be compressed according to the selected compression algorithm to obtain the compressed data;
压缩数据包生成单元,用于将所述压缩算法对应的标识添加到包头的第一指定位置,由所述压缩后的数据和包头生成压缩数据包。A compressed data packet generating unit, configured to add an identifier corresponding to the compression algorithm to the first designated position of the packet header, and generate a compressed data packet from the compressed data and the packet header.
结合第三方面,在第三方面的第一种可能实现方式中,所述装置还包括:With reference to the third aspect, in a first possible implementation manner of the third aspect, the apparatus further includes:
校验单元,用于对需要压缩的数据进行循环冗余校验,生成循环冗余校验结果;a verification unit, used to perform cyclic redundancy check on the data to be compressed, and generate a cyclic redundancy check result;
校验结果添加单元,用于将所述循环冗余校验结果添加到所述包头的第二指定位置。A verification result adding unit, configured to add the cyclic redundancy check result to the second specified position of the packet header.
结合第三方面,在第三方面的第二种可能实现方式中,所述装置还包括:With reference to the third aspect, in a second possible implementation manner of the third aspect, the apparatus further includes:
原始长度获取单元,用于获取压缩后的数据的长度以及需要压缩的数据的原始长度;The original length obtaining unit is used to obtain the length of the compressed data and the original length of the data to be compressed;
原始长度写入单元,用于将所述压缩后的数据的长度写入所述包头的第三指定位置,以及将需要压缩的数据的原始长度写入包头的第四指定位置。The original length writing unit is configured to write the length of the compressed data into the third designated position of the packet header, and write the original length of the data to be compressed into the fourth designated position of the packet header.
第四方面,本发明实施例提供了一种数据解压装置,所述装置包括:In a fourth aspect, an embodiment of the present invention provides a data decompression device, the device comprising:
数据获取单元,用于接收数据解压请求,获取压缩数据包中的压缩后的数据所对应的压缩算法对应的标识,以及在压缩数据包的指定位置获取压缩后的数据;a data acquisition unit, configured to receive a data decompression request, acquire an identifier corresponding to a compression algorithm corresponding to the compressed data in the compressed data packet, and obtain the compressed data at a specified position of the compressed data packet;
解压单元,用于根据所述标识查找对应的压缩算法,根据所述压缩算法对压缩后的数据进行解压缩,得到解压缩的数据。A decompression unit, configured to search for a corresponding compression algorithm according to the identifier, and decompress the compressed data according to the compression algorithm to obtain decompressed data.
在本发明中,在对数据进行压缩时,通过选择的压缩算法对需要压缩的数据进行压缩,并且将选择的压缩算法的标识添加包头的第一指定位置,由包头和压缩后的数据成生压缩数据包。当进行解压时,读取所述包头的第一指定位置的压缩算法的标识,调用对应的压缩算法对压缩的数据进行解压,得到解析的数据。通过压缩算法的标识的设定,可以使得本方法能够适应不同的算法的压缩文件的解压和压缩,有利于提高用户使用的便利性。In the present invention, when compressing data, the selected compression algorithm is used to compress the data to be compressed, and the identifier of the selected compression algorithm is added to the first designated position of the packet header, and the packet header and the compressed data are generated. Compressed packets. When performing decompression, the identifier of the compression algorithm in the first designated position of the packet header is read, and the corresponding compression algorithm is invoked to decompress the compressed data to obtain parsed data. By setting the identifier of the compression algorithm, the method can be adapted to the decompression and compression of compressed files of different algorithms, which is beneficial to improve the convenience of the user.
附图说明Description of drawings
图1是本发明第一实施例提供的数据压缩方法的实现流程图;Fig. 1 is the realization flow chart of the data compression method provided by the first embodiment of the present invention;
图2是本发明第二实施例提供的数据解压方法的实现流程图;Fig. 2 is the realization flow chart of the data decompression method provided by the second embodiment of the present invention;
图3是本发明第三实施例提供的数据压缩装置的结构示意图;3 is a schematic structural diagram of a data compression apparatus provided by a third embodiment of the present invention;
图4为本发明第三实施例提供的数据解压装置的结构示意图。FIG. 4 is a schematic structural diagram of a data decompression apparatus provided by a third embodiment of the present invention.
具体实施方式Detailed ways
为了使本发明的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本发明进行进一步详细说明。应当理解,此处所描述的具体实施例仅仅用以解释本发明,并不用于限定本发明。In order to make the objectives, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention, but not to limit the present invention.
本发明实施例的目的在于提供一种数据压缩方法和装置,以解决现有技术中由于压缩工具各种各样,并且不同的压缩工具所采用的压缩算法也会有所不同,导致不同的工具之间无法对压缩的数据包识别和解压。比如,当使用第一压缩算法的工具X进行文件压缩后,如果使用第二压缩算法的工具Y进行文件解压时可能会解压失败。因而导致用户需要在终端安装多个压缩工具,操作较为麻烦。The purpose of the embodiments of the present invention is to provide a data compression method and device, so as to solve the problem that in the prior art, due to various compression tools and different compression algorithms adopted by different compression tools, different tools Compressed packets cannot be identified and decompressed between. For example, after using the tool X of the first compression algorithm to compress the file, if the tool Y of the second compression algorithm is used to decompress the file, the decompression may fail. Therefore, the user needs to install multiple compression tools on the terminal, and the operation is troublesome.
实施例一:Example 1:
图1示出了本发明第一实施例提供的数据压缩方法的实现流程,详述如下:FIG. 1 shows the implementation process of the data compression method provided by the first embodiment of the present invention, and the details are as follows:
在步骤S101中,接收数据压缩请求,获取需要压缩的数据以及压缩所述数据所选择的压缩算法。In step S101, a data compression request is received, and the data to be compressed and the compression algorithm selected for compressing the data are obtained.
具体的,所述接收数据压缩请求,可以为用户需要对数据进行压缩时,调用本方法中的数据压缩程序接口,生成数据压缩请求。Specifically, the receiving the data compression request may be that when the user needs to compress the data, the data compression program interface in this method is invoked to generate the data compression request.
所述需要压缩的数据,也就是用户所选择的需要压缩的文件。所述文件可以为音频文件、视频文件、文本文件或者其它文件等。所述需要压缩的数据,可以为一个文件,也可以为多个文件的组合。The data that needs to be compressed, that is, the file that needs to be compressed selected by the user. The files may be audio files, video files, text files, or other files, and the like. The data to be compressed may be one file or a combination of multiple files.
所述压缩数据所选择的压缩算法,可以在得到需要压缩的数据后,对待压缩的数据取样本进行压缩测试分析和判断。比如,判断需要压缩的数据为视频文件,或者判断需要压缩的数据为音频文件,或者判断需要压缩的数据为文本文件等,根据文件的样本数据测试压缩结果,查找那种压缩算法压缩效果好,就选择那种压缩算法。当然,还可以根据用户的选择请求,由用户选择压缩算法。The compression algorithm selected for the compressed data may, after obtaining the data to be compressed, take a sample of the data to be compressed to perform compression test analysis and judgment. For example, judging that the data to be compressed is a video file, or that the data to be compressed is an audio file, or that the data to be compressed is a text file, etc., test the compression result according to the sample data of the file, and find out which compression algorithm has a good compression effect. Just choose that compression algorithm. Of course, the compression algorithm may also be selected by the user according to the user's selection request.
所述压缩算法可以预先集成在本方法所对应的压缩工具中,或者可以将压缩算法集成在服务器中,当压缩工具选择了对应的压缩算法后,在本地或者服务器中获取对应的压缩算法。The compression algorithm may be pre-integrated in the compression tool corresponding to the method, or the compression algorithm may be integrated in the server. After the compression tool selects the corresponding compression algorithm, the corresponding compression algorithm is obtained locally or in the server.
在步骤S102中,根据所选择的压缩算法对需要压缩的数据进行压缩,得到压缩后的数据。In step S102, the data to be compressed is compressed according to the selected compression algorithm to obtain compressed data.
在步骤S101中选择了压缩算法后,根据选择的压缩算法,对需要压缩的数据进行压缩,得到压缩后的数据。所述压缩后的数据所占用的存储空间小于所述需要压缩的数据所占用的存储空间。After the compression algorithm is selected in step S101, the data to be compressed is compressed according to the selected compression algorithm to obtain compressed data. The storage space occupied by the compressed data is smaller than the storage space occupied by the data to be compressed.
在步骤S103中,将所述压缩算法对应的标识添加到包头的第一指定位置,由所述压缩后的数据和包头生成压缩数据包。In step S103, the identifier corresponding to the compression algorithm is added to the first designated position of the packet header, and a compressed data packet is generated from the compressed data and the packet header.
根据选择的压缩算法,可以查找到所述压缩算法对应的标识。可以设置压缩算法与标识的对应关系,将压缩算法的类型通过少量的字节记录在包头的第一指定位置。比如,所述第一指定位置可以为少量的字节,可以为4个字节。According to the selected compression algorithm, the identifier corresponding to the compression algorithm can be found. The corresponding relationship between the compression algorithm and the identifier can be set, and the type of the compression algorithm is recorded in the first specified position of the packet header through a small number of bytes. For example, the first specified position may be a small number of bytes, and may be 4 bytes.
所述压缩的数据和包头成生压缩数据包后,即可对压缩后的数据包进行保存或者传输,可以供其它压缩工具进行解压操作,或者供本方法所对应的工具在其它设备中进行解压操作,得到解压后的数据,即压缩前的数据。After the compressed data and the packet header are generated to generate a compressed data packet, the compressed data packet can be saved or transmitted, and can be used for decompression operations by other compression tools, or for tools corresponding to this method to be decompressed in other devices. operation to obtain the decompressed data, that is, the data before compression.
当然,作为本发明进一步优化的实施方式中,在所述接收数据压缩请求,获取需要压缩的数据以及选择压缩所述数据所选择的压缩算法的步骤之后,所述方法还包括:对需要压缩的数据进行循环冗余校验,生成循环冗余校验结果;将所述循环冗余校验结果添加到所述包头的第二指定位置。Of course, in a further optimized embodiment of the present invention, after the steps of receiving a data compression request, acquiring the data to be compressed, and selecting a compression algorithm selected for compressing the data, the method further includes: compressing the data to be compressed. The data is subjected to a cyclic redundancy check to generate a cyclic redundancy check result; and the cyclic redundancy check result is added to the second designated position of the packet header.
所述包头可以设置第二指定位置,并在第二指定位置中存储循环冗余校验结果。其中,所述循环冗余校验结果是对需要压缩的数据进行循环冗余校验所生成。通过设置循环冗余校验结果,当对压缩包进行解压时,可以对解压后的数据进行循环冗余校验,从而验证压缩后的数据是否完整。如果校验出错,则说明压缩或者解压过程中,有数据丢失或者出错。The packet header may set a second designated location, and store the CRC result in the second designated location. Wherein, the cyclic redundancy check result is generated by performing cyclic redundancy check on the data to be compressed. By setting the cyclic redundancy check result, when the compressed package is decompressed, the cyclic redundancy check can be performed on the decompressed data, so as to verify whether the compressed data is complete. If there is an error in the verification, it means that there is data loss or error during the compression or decompression process.
另外,进一步的优化方式中,在所述接收数据压缩请求,获取需要压缩的数据以及选择压缩所述数据所选择的压缩算法的步骤之后,所述方法还包括:In addition, in a further optimized manner, after the steps of receiving a data compression request, acquiring the data to be compressed, and selecting a compression algorithm selected for compressing the data, the method further includes:
获取压缩后的数据的长度以及需要压缩的数据的原始长度;将所述压缩后的数据的长度写入所述包头的第三指定位置,以及将需要压缩的数据的原始长度写入包头的第四指定位置。Obtain the length of the compressed data and the original length of the data to be compressed; write the length of the compressed data into the third specified position of the packet header, and write the original length of the data to be compressed into the third specified position of the packet header. Four designated locations.
通过在包头设置压缩后的数据的长度,以及需要压缩的数据的原始长度。当用户对压缩包进行解压时,可以先根据包头中存储的压缩后的数据的长度,判断当前压缩后的数据的长度是否与第三指定位置存储的长度相符。如果相符则执行后续的解压操作,并且判断解压后的数据的长度是否与第四指定位置存储的长度相符,如果不相符则会发出报错提醒。By setting the length of the compressed data in the packet header, and the original length of the data to be compressed. When the user decompresses the compressed package, he may first determine whether the length of the currently compressed data matches the length stored in the third designated location according to the length of the compressed data stored in the header. If it matches, the subsequent decompression operation is performed, and it is judged whether the length of the decompressed data matches the length stored in the fourth designated location, and if not, an error notification will be issued.
本发明所述数据压缩方法,可以选择所需要的压缩算法对需要压缩的数据进行压缩,因而可以生成不同压缩算法所对应的压缩包。可以适应不同解压工具的要求。并且采用与本方法对应的,如图2所示的解压方法,可以直接对不同算法压缩的数据包进行解压,大大的提高了用户使用的便利性。In the data compression method of the present invention, the required compression algorithm can be selected to compress the data to be compressed, so that compressed packets corresponding to different compression algorithms can be generated. Can adapt to the requirements of different decompression tools. And by using the decompression method corresponding to this method, as shown in FIG. 2 , the data packets compressed by different algorithms can be directly decompressed, which greatly improves the convenience of the user.
实施例二:Embodiment 2:
图2示出了本发明第二实施例提供的数据解压方法的实现流程,详述如下:FIG. 2 shows the implementation process of the data decompression method provided by the second embodiment of the present invention, which is described in detail as follows:
在步骤S201中,接收数据解压请求,获取压缩数据包中的压缩后的数据所对应的压缩算法对应的标识,以及在压缩数据包的指定位置获取压缩后的数据。In step S201, a data decompression request is received, an identifier corresponding to a compression algorithm corresponding to the compressed data in the compressed data packet is obtained, and the compressed data is obtained at a specified position of the compressed data packet.
与实施例一中的压缩方法对应的,本发明所述解压方法,接收数据解压请求,可以通过调用本方法中的数据解压缩程序接口,发起解压请求,或者通过打开本方法对应的工具,在工具中触发解压指令。Corresponding to the compression method in Embodiment 1, the decompression method of the present invention, when receiving a data decompression request, can initiate a decompression request by calling the data decompression program interface in this method, or by opening the tool corresponding to this method, in the The decompression command is triggered in the tool.
在对压缩包进行解压时,首先获取压缩数据包的包头的压缩算法的标识,以及所述压缩数据包的指定位置获取压缩后的数据。所述压缩后的数据可以存放在所述压缩数据包的包头的后面。When decompressing the compressed packet, firstly, the identifier of the compression algorithm of the header of the compressed data packet is obtained, and the compressed data is obtained from the specified position of the compressed data packet. The compressed data may be stored after the header of the compressed data packet.
在步骤S202中,根据所述标识查找对应的压缩算法,根据所述压缩算法对压缩后的数据进行解压缩,得到解压缩的数据。In step S202, a corresponding compression algorithm is searched according to the identifier, and the compressed data is decompressed according to the compression algorithm to obtain decompressed data.
根据所述压缩算法对应的标识,可以查找到对应的压缩算法。根据查找到的压缩算法,可以对压缩数据包中的压缩后的数据进行解压操作,可以适应不同压缩算法所对应的压缩后的数据的解压要求。According to the identifier corresponding to the compression algorithm, the corresponding compression algorithm can be found. According to the found compression algorithm, the compressed data in the compressed data packet can be decompressed, and the decompression requirements of the compressed data corresponding to different compression algorithms can be adapted.
当然,所述压缩算法可以存储在本方法所对应的工具中,也可以存储在服务器中,当查找到对应的压缩算法后,可以从本地获取对应的压缩算法,也可以从服务器获取对应的压缩算法。Of course, the compression algorithm can be stored in the tool corresponding to this method, or stored in the server. When the corresponding compression algorithm is found, the corresponding compression algorithm can be obtained locally, or the corresponding compression algorithm can be obtained from the server. algorithm.
另外,作为本发明进一步优化,在所述根据所述标识查找对应的压缩算法,根据所述压缩算法对压缩后的数据进行解压缩,得到解压缩的数据步骤之后,所述方法还包括:In addition, as a further optimization of the present invention, after the step of searching for a corresponding compression algorithm according to the identifier, decompressing the compressed data according to the compression algorithm, and obtaining decompressed data, the method further includes:
通过循环结果校验方法对解压的数据进行校验,生成解压数据的校验结果;将所述解压数据的校验结果与存储在包头第二指定位置的校验结果进行比较,根据比较结果判断所述解压的数据的完整性。The decompressed data is verified by the cyclic result verification method to generate the verification result of the decompressed data; the verification result of the decompressed data is compared with the verification result stored in the second designated position of the packet header, and the judgment is made according to the comparison result. The integrity of the decompressed data.
通过在包头设置循环校验结果,可以对解压后的数据进行校验,及时发现解压后的数据是否有过修改或者数据丢失。By setting the cyclic verification result in the packet header, the decompressed data can be verified, and whether the decompressed data has been modified or the data has been lost can be found in time.
另外,与实施例一中优化方式对应的,在所述根据所述标识查找对应的压缩算法,根据所述压缩算法对压缩后的数据进行解压缩,得到解压缩的数据步骤之前,所述方法还包括:In addition, corresponding to the optimization method in the first embodiment, before the step of searching for the corresponding compression algorithm according to the identifier, decompressing the compressed data according to the compression algorithm, and obtaining the decompressed data, the method Also includes:
获取包头的第三指定位置中存储的压缩后的数据的长度,以及所述压缩数据包中的压缩后的数据的长度,根据压缩后的数据的长度与存储的长度的比较结果判断数据是否完整;Obtain the length of the compressed data stored in the third designated position of the packet header, and the length of the compressed data in the compressed data packet, and judge whether the data is complete according to the comparison result of the length of the compressed data and the stored length ;
以及在所述根据所述标识查找对应的压缩算法,根据所述压缩算法对压缩后的数据进行解压缩,得到解压缩的数据步骤之后,所述方法还包括:And after the step of searching for a corresponding compression algorithm according to the identifier, decompressing the compressed data according to the compression algorithm, and obtaining decompressed data, the method further includes:
获取包头的第四指定位置存储的压缩前的数据的长度,以及解压缩的数据的长度,根据解压缩的数据的长度与存储的长度的比较结果判断解压后的数据是否完整。Obtain the length of the data before compression and the length of the decompressed data stored in the fourth designated position of the packet header, and determine whether the decompressed data is complete according to the comparison result between the length of the decompressed data and the stored length.
通过在包头的第一指定位置查找压缩算法所对应的标识,并根据查找的压缩算法,对压缩后的数据进行解压,因而本方法可以适应不同压缩工具所压缩后的数据的解压要求。有利于提高用户使用的方便性。并且通过与本方法对应的压缩方法生成压缩数据包,可大大的提高用户对数据采用不同压缩算法的需求。By searching the identifier corresponding to the compression algorithm at the first designated position of the packet header, and decompressing the compressed data according to the searched compression algorithm, the method can adapt to the decompression requirements of the data compressed by different compression tools. It is beneficial to improve the convenience for users to use. And the compressed data packet is generated by the compression method corresponding to the present method, which can greatly improve the user's demand for using different compression algorithms for data.
实施例三:Embodiment three:
图3示出了本发明第三实施例提供的数据压缩装置的结构示意图,详述如下:FIG. 3 shows a schematic structural diagram of a data compression apparatus provided by a third embodiment of the present invention, and details are as follows:
本发明实施例所述数据压缩装置,包括:The data compression device according to the embodiment of the present invention includes:
请求单元301,用于接收数据压缩请求,获取需要压缩的数据以及压缩所述数据所选择的压缩算法;A requesting
压缩单元302,用于根据所选择的压缩算法对需要压缩的数据进行压缩,得到压缩后的数据;A
压缩数据包生成单元303,用于将所述压缩算法对应的标识添加到包头的第一指定位置,由所述压缩后的数据和包头生成压缩数据包。The compressed data
优选的,所述装置还包括:Preferably, the device further includes:
校验单元,用于对需要压缩的数据进行循环冗余校验,生成循环冗余校验结果;a verification unit, used to perform cyclic redundancy check on the data to be compressed, and generate a cyclic redundancy check result;
校验结果添加单元,用于将所述循环冗余校验结果添加到所述包头的第二指定位置。A verification result adding unit, configured to add the cyclic redundancy check result to the second specified position of the packet header.
优选的,所述装置还包括:Preferably, the device further includes:
原始长度获取单元,用于获取压缩后的数据的长度以及需要压缩的数据的原始长度;The original length obtaining unit is used to obtain the length of the compressed data and the original length of the data to be compressed;
原始长度写入单元,用于将所述压缩后的数据的长度写入所述包头的第三指定位置,以及将需要压缩的数据的原始长度写入包头的第四指定位置。The original length writing unit is configured to write the length of the compressed data into the third designated position of the packet header, and write the original length of the data to be compressed into the fourth designated position of the packet header.
图3所述数据压缩装置,与图1所述数据压缩方法对应,在此不作重复的描述。The data compression apparatus shown in FIG. 3 corresponds to the data compression method shown in FIG. 1 , and the description is not repeated here.
另外,本发明还提供了一种数据解压装置,如图4所示,所述数据解压装置,包括:In addition, the present invention also provides a data decompression device, as shown in FIG. 4 , the data decompression device includes:
数据获取单元401,用于接收数据解压请求,获取压缩数据包中的压缩后的数据所对应的压缩算法对应的标识,以及在压缩数据包的指定位置获取压缩后的数据;The
解压单元402,用于根据所述标识查找对应的压缩算法,根据所述压缩算法对压缩后的数据进行解压缩,得到解压缩的数据。The
优选的,所述装置还包括:Preferably, the device further includes:
校验结果生成单元,用于通过循环结果校验方法对解压的数据进行校验,生成解压数据的校验结果;a verification result generation unit, configured to verify the decompressed data by a cyclic result verification method, and generate a verification result of the decompressed data;
校验结果比较单元,用于将所述解压数据的校验结果与存储在包头第二指定位置的校验结果进行比较,根据比较结果判断所述解压的数据的完整性。The verification result comparison unit is configured to compare the verification result of the decompressed data with the verification result stored in the second specified position of the packet header, and judge the integrity of the decompressed data according to the comparison result.
优选的,所述装置还包括:Preferably, the device further includes:
第一长度比较单元,用于获取包头的第三指定位置中存储的压缩后的数据的长度,以及所述压缩数据包中的压缩后的数据的长度,根据压缩后的数据的长度与存储的长度的比较结果判断数据是否完整;The first length comparison unit is used to obtain the length of the compressed data stored in the third specified position of the packet header, and the length of the compressed data in the compressed data packet, according to the length of the compressed data and the stored data. The comparison result of the length judges whether the data is complete;
第二长度比较单元,用于获取包头的第四指定位置存储的压缩前的数据的长度,以及解压缩的数据的长度,根据解压缩的数据的长度与存储的长度的比较结果判断解压后的数据是否完整。The second length comparison unit is used to obtain the length of the data before compression stored in the fourth designated position of the packet header, and the length of the decompressed data, and judge the decompressed data according to the comparison result between the length of the decompressed data and the stored length. Is the data complete.
本发明实施例中所述数据压缩装置、数据解压装置,分别与实施例一中所述数据压缩方法、实施例二中的数据解压方法对应。The data compression apparatus and the data decompression apparatus described in the embodiments of the present invention correspond to the data compression method described in Embodiment 1 and the data decompression method described in Embodiment 2, respectively.
在本发明所提供的几个实施例中,应该理解到,所揭露的装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided by the present invention, it should be understood that the disclosed apparatus and method may be implemented in other manners. For example, the apparatus embodiments described above are only illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components may be combined or Can be integrated into another system, or some features can be ignored, or not implemented. On the other hand, the shown or discussed mutual coupling or direct coupling or communication connection may be through some interfaces, indirect coupling or communication connection of devices or units, and may be in electrical, mechanical or other forms.
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described as separate components may or may not be physically separated, and components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution in this embodiment.
另外,在本发明各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit. The above-mentioned integrated units may be implemented in the form of hardware, or may be implemented in the form of software functional units.
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本发明各个实施例所述方法的全部或部分。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。The integrated unit, if implemented in the form of a software functional unit and sold or used as an independent product, may be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium , including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, Read-Only Memory (ROM, Read-Only Memory), Random Access Memory (RAM, Random Access Memory), magnetic disk or optical disk and other media that can store program codes .
以上所述仅为本发明的较佳实施例而已,并不用以限制本发明,凡在本发明的精神和原则之内所作的任何修改、等同替换和改进等,均应包含在本发明的保护范围之内。The above descriptions are only preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent replacements and improvements made within the spirit and principles of the present invention shall be included in the protection of the present invention. within the range.
Claims (7)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710108980.0A CN106936441B (en) | 2017-02-27 | 2017-02-27 | A data compression method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710108980.0A CN106936441B (en) | 2017-02-27 | 2017-02-27 | A data compression method and device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN106936441A CN106936441A (en) | 2017-07-07 |
CN106936441B true CN106936441B (en) | 2020-08-21 |
Family
ID=59424163
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201710108980.0A Active CN106936441B (en) | 2017-02-27 | 2017-02-27 | A data compression method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN106936441B (en) |
Families Citing this family (15)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107423397B (en) * | 2017-07-26 | 2020-05-19 | 北京时代民芯科技有限公司 | Adaptive compression storage and decompression extraction method for multitask micro-system |
CN108268658B (en) * | 2018-02-06 | 2021-02-26 | 政采云有限公司 | MySQL database-based large text field storage method and system |
CN109274377A (en) * | 2018-08-22 | 2019-01-25 | 泰康保险集团股份有限公司 | Data processing method, device, medium and the electronic equipment of block chain network |
CN108958966A (en) * | 2018-09-27 | 2018-12-07 | 合肥达博科技有限公司 | A kind of data guard method and device of lossless data compression |
CN109683872A (en) * | 2018-11-08 | 2019-04-26 | 广州视源电子科技股份有限公司 | Webpage script processing and decompressing method, device and system |
CN109634529A (en) * | 2018-12-12 | 2019-04-16 | 浪潮(北京)电子信息产业有限公司 | A kind of data compression method and decompressing method |
CN111385268B (en) * | 2018-12-29 | 2023-02-24 | 大唐移动通信设备有限公司 | Data packet header compression confirmation method and communication equipment |
CN111835686A (en) * | 2019-04-19 | 2020-10-27 | 百度在线网络技术(北京)有限公司 | Data compression method, data decompression method, data compression device, data decompression device, electronic equipment and storage medium |
CN110430168A (en) * | 2019-07-05 | 2019-11-08 | 视联动力信息技术股份有限公司 | A kind of method and apparatus of data compression |
CN111337133B (en) | 2020-03-02 | 2021-08-03 | 浙江大华技术股份有限公司 | Infrared data generation method and device and infrared data analysis method and device |
CN111552669A (en) * | 2020-04-26 | 2020-08-18 | 北京达佳互联信息技术有限公司 | Data processing method, apparatus, computing device and storage medium |
CN112487880B (en) * | 2020-11-13 | 2021-09-24 | 河北省科学院应用数学研究所 | Median filter, device and system based on maximum error criterion |
CN112559463B (en) * | 2020-12-18 | 2023-08-25 | 杭州数梦工场科技有限公司 | Compressed file processing method and device |
CN115809221A (en) | 2021-09-15 | 2023-03-17 | 华为技术有限公司 | Data compression method and device |
CN114817160A (en) * | 2022-04-08 | 2022-07-29 | 深圳Tcl新技术有限公司 | File decompression method and device, electronic equipment and computer readable storage medium |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101478370A (en) * | 2009-01-20 | 2009-07-08 | 中兴通讯股份有限公司 | File compression method and apparatus based on file system |
CN101841337A (en) * | 2010-05-06 | 2010-09-22 | 华为终端有限公司 | Data compression and decompression processing method and mobile storage device |
CN104796155A (en) * | 2012-05-30 | 2015-07-22 | 北京奇虎科技有限公司 | Data compression method and device |
US9112525B1 (en) * | 2014-03-28 | 2015-08-18 | Comtech Ef Data Corp. | System and method for parallel hash-based data compression |
-
2017
- 2017-02-27 CN CN201710108980.0A patent/CN106936441B/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101478370A (en) * | 2009-01-20 | 2009-07-08 | 中兴通讯股份有限公司 | File compression method and apparatus based on file system |
CN101841337A (en) * | 2010-05-06 | 2010-09-22 | 华为终端有限公司 | Data compression and decompression processing method and mobile storage device |
CN104796155A (en) * | 2012-05-30 | 2015-07-22 | 北京奇虎科技有限公司 | Data compression method and device |
US9112525B1 (en) * | 2014-03-28 | 2015-08-18 | Comtech Ef Data Corp. | System and method for parallel hash-based data compression |
Also Published As
Publication number | Publication date |
---|---|
CN106936441A (en) | 2017-07-07 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN106936441B (en) | A data compression method and device | |
CN106980625B (en) | Data synchronization method, device and system | |
CN103348334B (en) | Cloud system and the compressing file in cloud system and transfer approach | |
CN111190928A (en) | Cache processing method, apparatus, computer equipment, and storage medium | |
CN107436844B (en) | Method and device for generating interface use case collection | |
CN106201783B (en) | A kind of data reconstruction method and device | |
US10649905B2 (en) | Method and apparatus for storing data | |
US20130067237A1 (en) | Providing random access to archives with block maps | |
CN111935227A (en) | Method for uploading file through browser, browser and electronic equipment | |
CN107689976A (en) | A kind of document transmission method and device | |
CN112804312B (en) | File uploading method, equipment and computer readable medium | |
CN102255866A (en) | Method and device for downloading data | |
CN107196998A (en) | Mobile Web request processing method, equipment and system based on data deduplication | |
CN113014510A (en) | Data caching method and device in distributed test of inertial navigation system | |
CN112436943B (en) | Request deduplication method, device, equipment and storage medium based on big data | |
CN106302604B (en) | Data transmission method and device | |
US20120324560A1 (en) | Token data operations | |
CN113407508B (en) | Method, system, equipment and medium for compressing log file | |
US20170039259A1 (en) | Method and Apparatus for Implementing Storage of File in IP Disk | |
CN108133026B (en) | Multi-data processing method, system and storage medium | |
CN111427917A (en) | Search data processing method and related product | |
CN115859232A (en) | Electronic asset right-determining service processing method and device, electronic equipment and storage medium | |
CN114238264A (en) | Data processing method, apparatus, computer equipment and storage medium | |
CN109086172B (en) | A data processing method and related device | |
CN104424238B (en) | A kind of method, apparatus that mass file generates |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
CB03 | Change of inventor or designer information | ||
CB03 | Change of inventor or designer information |
Inventor after: Gao Ning Inventor after: Yu Bing Inventor before: Yu Bing |
|
CB02 | Change of applicant information | ||
CB02 | Change of applicant information |
Address after: 518000 12th Floor, Building A4, Nanshan Zhiyuan, 1001 Xueyuan Avenue, Nanshan District, Shenzhen City, Guangdong Province Applicant after: Shenzhen Guotaian Educational Technology Co., Ltd. Address before: 518000 Checkpoint, Nantou, Shenzhen, Guangdong Province, 30 Building 3, Zhiheng Industrial Park, Gate 2, Nanshan District, Shenzhen Applicant before: GTA INFORMATION TECHNOLOGY CO., LTD. (GTA) |
|
GR01 | Patent grant | ||
GR01 | Patent grant | ||
TR01 | Transfer of patent right | ||
TR01 | Transfer of patent right |
Effective date of registration: 20211216 Address after: 518000 Room 201, building A, No. 1, Qian Wan Road, Qianhai Shenzhen Hong Kong cooperation zone, Shenzhen, Guangdong (Shenzhen Qianhai business secretary Co., Ltd.) Patentee after: Shenzhen guotengan Vocational Education Technology Co.,Ltd. Address before: 518000 12th Floor, Building A4, Nanshan Zhiyuan, 1001 Xueyuan Avenue, Nanshan District, Shenzhen City, Guangdong Province Patentee before: SHENZHEN GTA EDUCATION TECH Ltd. |