Summary of the invention
The invention provides a kind of data compression method and device, can not according to the problem needing to select suitable compression algorithm of oneself owing to lacking professional knowledge to solve user in prior art.
The invention provides a kind of data compression method, comprising: call packed data statistical form, wherein, in packed data statistical form, preserve the one-to-one relationship between data format, compressed configuration and compression effectiveness information; From packed data statistical form, corresponding compression effectiveness information is obtained according to the compact model that data format and the user of data to be compressed select, and the compressed configuration corresponding with compact model according to compression effectiveness Information Selection, wherein, compact model comprises: compression speed mode of priority and compression volume mode of priority; Treat packed data according to compressed configuration to compress, obtain compressed data packets.
Preferably, compression effectiveness information comprises: compression time.
Preferably, from packed data statistical form, corresponding compression effectiveness information is obtained according to the compact model that data format and the user of data to be compressed select, and the compressed configuration corresponding with compact model according to compression effectiveness Information Selection specifically comprises: when the compact model that user selects is compression speed mode of priority, obtain the data format of data to be compressed; The compression time of data format under different compressed configuration is obtained from packed data statistical form; The fastest compressed configuration of compression speed is obtained according to compression time.
Preferably, before calling packed data statistical form, said method also comprises: according to the data format of data to be compressed, treats packed data and filters, and filters out by compressed data, obtain not by compressed data,
Preferably, treat after packed data compresses according to compressed configuration, method also comprises: by being directly stored in compressed data packets by compressed data of filtering out.
Preferably, compression effectiveness information comprises: compressed data packets size.
Preferably, from packed data statistical form, corresponding compression effectiveness information is obtained according to the compact model that data format and the user of data to be compressed select, and the compressed configuration corresponding with compact model according to compression effectiveness Information Selection specifically comprises: when the compact model that user selects is compression volume mode of priority, obtain the data format of data to be compressed; The compressed data packets size of data format under different compressed configuration is obtained from packed data statistical form; According to the compressed configuration that compressed data packets acquiring size compressed data packets volume is minimum.
Preferably, compressed configuration comprises: compression algorithm and compression parameters.
Preferably, data to be compressed comprise the data of one or more different data format; Treat packed data according to compressed configuration to compress, obtain compressed data packets and specifically comprise: the compressed configuration corresponding according to each different data format is treated the data of each different data format in packed data respectively and compressed, obtain compressed data packets.
Present invention also offers a kind of data compression device, comprising: calling module, for calling packed data statistical form, wherein, in packed data statistical form, preserving the one-to-one relationship between data format, compressed configuration and compression effectiveness information; Select module, compact model for selecting according to data format and the user of data to be compressed obtains corresponding compression effectiveness information from packed data statistical form, and the compressed configuration corresponding with compact model according to compression effectiveness Information Selection, wherein, compact model comprises: compression speed mode of priority and compression volume mode of priority; Compression module, compresses for treating packed data according to compressed configuration, obtains compressed data packets.
Preferably, compression effectiveness information comprises: compression time.
Preferably, select module specifically for: when user select compact model be compression speed mode of priority, obtain the data format of data to be compressed; The compression time of data format under different compressed configuration is obtained from packed data statistical form; The fastest compressed configuration of compression speed is obtained according to compression time.
Preferably, said apparatus also comprises: filtering module, before calling packed data statistical form at calling module, according to the data format of data to be compressed, treat packed data to filter, filter out by compressed data, obtain not by compressed data; Memory module, for treat after packed data compresses according to compressed configuration at compression module, by being directly stored in compressed data packets by compressed data of filtering out.
Preferably, compression effectiveness information comprises: compressed data packets size.
Preferably, select module specifically for: when user select compact model be compression volume mode of priority, obtain the data format of data to be compressed; The compressed data packets size of data format under different compressed configuration is obtained from packed data statistical form; According to the compressed configuration that compressed data packets acquiring size compressed data packets volume is minimum.
Preferably, compressed configuration comprises: compression algorithm and compression parameters.
Preferably, data to be compressed comprise the data of one or more different data format; Compression module specifically for: the compressed configuration corresponding according to each different data format is treated the data of each different data format in packed data respectively and is compressed, obtain compressed data packets.
Beneficial effect of the present invention is as follows:
The compressed configuration data to user corresponding with the compact model that user selects by the Intelligent Matching when compressed file are compressed, solving user in prior art can not according to the problem needing to select suitable compression algorithm of oneself owing to lacking professional knowledge, the technical scheme of the embodiment of the present invention can according to the needs of user, automatically for user mates most suitable compressed configuration, thus reaching the object that compression speed is the fastest or compression volume is minimum, the use sense that improve user is subject to.
Embodiment
Can not according to the problem needing to select suitable compression algorithm of oneself owing to lacking professional knowledge in order to solve user in prior art, the invention provides a kind of data compression method and device, the technical scheme of the embodiment of the present invention can according to the compact model of user's selection, automatically for user selects suitable compressed configuration, thus reach the compression object of user.Below in conjunction with accompanying drawing and embodiment, the present invention is further elaborated.Should be appreciated that specific embodiment described herein only in order to explain the present invention, do not limit the present invention.
Embodiment of the method
According to embodiments of the invention, provide a kind of data compression method, Fig. 2 is the flow chart of the data compression method of the embodiment of the present invention, as shown in Figure 2, comprises following process according to the data compression method of the embodiment of the present invention:
Step 201, calls packed data statistical form, wherein, preserves the one-to-one relationship between data format, compressed configuration and compression effectiveness information in packed data statistical form.
Preferably, above-mentioned compressed configuration comprises: compression algorithm and compression parameters; Above-mentioned compression effectiveness information comprises: compression time and compressed data packets size.In actual applications, compression algorithm comprises: the cab compression algorithm etc. of the zip compression algorithm that the rar compression algorithm that compressed data packets is rar form, compressed data packets are zip form, compressed data packets to be the 7z compression algorithm of 7z form and compressed data packets be cab form.Compression parameters comprises: whether encrypt, solid (Solid) compression parameters and compression after whether delete the parameters such as source file.
In actual applications, packed data statistical form be in a large amount of experiments to various different file format (namely, above-mentioned data format) performance under different compression algorithms carries out adding up obtaining, in packed data statistical form, comprise the statistics of different compressed configuration in speed (calculating of speed carries out under same hardware environment) and compression ratio two, during for compressing file, the most suitable compressed configuration of Intelligent Matching provides foundation, thus reaches fastest or the object of compression ratio minimum (after compression, volume is minimum).It should be noted that, in embodiments of the present invention, the computational methods of compression ratio are: compression ratio=compressed data packets size/size of data to be compressed.As shown in table 1 according to the packed data statistical form of the embodiment of the present invention:
Table 1
It should be noted that, each data in table 1 are only and illustrate, are not the actual experimental data recorded.
Step 202, from packed data statistical form, corresponding compression effectiveness information is obtained according to the compact model that data format and the user of data to be compressed select, and the compressed configuration corresponding with compact model according to compression effectiveness Information Selection, wherein, compact model comprises: compression speed mode of priority and compression volume mode of priority;
When the compact model that user selects is compression speed mode of priority, step 202 specifically comprises following process:
1, obtain the data format of data to be compressed, such as, data format is .gif;
2, from packed data statistical form, obtain the compression time of this data format under different compressed configuration, such as, as shown in table 1, when data format is .gif, under rar compression algorithm, compression time is 5s, and under zip compression algorithm, compression time is 2s; In actual applications, statistics in packed data statistical form is all compress the statistics that data that front size is 1M carry out for benchmark, but, when carrying out data compression, the size needing the data of compression is indefinite, in actual applications, only can be as the criterion with the compression time added up in packed data statistical form and compare, also the anticipated compression deadline of current data to be compressed can be calculated according to volume ratio, and with this anticipated compression deadline for benchmark compares.
3, obtain the fastest compressed configuration of compression speed according to compression time, such as, when data format is .gif, the compression time obtained from table 1 is respectively 5s and 2s, the zip compression algorithm of compressed configuration corresponding to 2s that compression speed is the fastest.
By above-mentioned process, user can be helped to select optimum compressed configuration intelligently thus realize the fastest object of compression speed.
In embodiments of the present invention, compression speed mode of priority is not give no thought to compressing file rate, but calculates under the prerequisite being standard with compress mode, under the prerequisite that sacrifice compression ratio is not very large, obtain the fastest speed.Be implemented as follows:
Experimentally add up, for the data to be compressed of most of form, what compression speed was the fastest is zip compression algorithm, and for a part by the data such as picture, audio-video document, document compressed, then compression ratio when compressing is very high, when the high threshold value to pre-setting of compression ratio (such as, threshold value is 98%) time, intelligence can skip these file types under compression speed mode of priority, that is, above-mentioned file not compressed.
Particularly, when the compact model that user selects is compression speed mode of priority, before calling packed data statistical form, first according to the data format of data to be compressed, treat packed data to filter, filter out by compressed data (such as, by the data such as picture, audio-video document, document compressed), obtain not by compressed data.Subsequently, step 201 is not performed by compressed data to be compressed to what obtain.Such as: the technical scheme of the embodiment of the present invention automatically skips the file of rmvb form (or skipping compressed alternative document), alternative document is adopted to the zip compression algorithm of standard.
When the compact model that user selects is compression volume mode of priority, step 202 specifically comprises following process:
1, the data format of data to be compressed is obtained; Such as, data format is .gif;
2, from packed data statistical form, obtain the compressed data packets size of data format under different compressed configuration; Such as, as shown in table 1, when data format is .gif, under rar compression algorithm, compressed data packets size is 7M, and under zip compression algorithm, compressed data packets size is 9M; In actual applications, statistics in packed data statistical form is all compress data that front size is 1M to be as the criterion the statistics of carrying out, but, when carrying out data compression, the size of data to be compressed is indefinite, in actual applications, can only with the compressed data packets size of adding up in packed data statistical form for benchmark compares, also the anticipated compression data package size of current data to be compressed can be calculated according to volume ratio, and with this anticipated compression data package size for benchmark compares.
3, according to the compressed configuration that compressed data packets acquiring size compressed data packets volume is minimum.Such as, the compressed data packets size obtained from table 1 is respectively 7M and 9M, the rar compression algorithm of compressed configuration corresponding to 7M that compressed data packets is minimum.
It should be noted that, experimentally add up, solid compression parameters can allow compression ratio lower, therefore, the experiment statistics in packed data statistical form be all the data of solid compression.And for most of formatted file, what compression ratio was the highest is all 7z form, and only have the file types such as indivedual picture, audio-video document, document, the compression ratio of rar form is even better.Such as, the technical scheme of the embodiment of the present invention uses rar compression algorithm for data types such as indivedual picture, audio-video document, documents, and configure solid compression parameters and compress, 7z compression algorithm is adopted to alternative document, and configures solid compression parameters and compress.
By above-mentioned process, user can be helped to select optimum compressed configuration intelligently thus realize the minimum object of compressed data packets.
Preferably, in embodiments of the present invention, user can also manually select compressed configuration.
Step 203, treats packed data according to compressed configuration and compresses, and obtains compressed data packets.
It should be noted that, if before calling packed data statistical form, treat packed data and carried out filter operation, so, after treating packed data and compressing, need being directly stored in this compressed data packets by compressed data of filtering out.
It should be noted that, data to be compressed can comprise the data of one or more different data format, therefore, in actual applications, need from packed data statistical form, obtain the compressed configuration corresponding respectively with each data format in data to be compressed, when data to be compressed are compressed, need the compressed configuration corresponding according to each different data format to treat the data of each different data format in packed data and compress respectively, obtain compressed data packets.
In sum, by means of the technical scheme of the embodiment of the present invention, the compressed configuration data to user corresponding with the compact model that user selects by the Intelligent Matching when compressed file are compressed, solving user in prior art can not according to the problem needing to select suitable compression algorithm of oneself owing to lacking professional knowledge, the technical scheme of the embodiment of the present invention can according to the needs of user, automatically for user mates most suitable compressed configuration, thus reaching the object that compression speed is the fastest or compression volume is minimum, the use sense that improve user is subject to.
Device embodiment
According to embodiments of the invention, provide a kind of data compression device, Fig. 3 is the structural representation of the data compression device of the embodiment of the present invention, as shown in Figure 3, data compression device according to the embodiment of the present invention comprises: calling module 30, selection module 32 and compression module 34, be described in detail the modules of the embodiment of the present invention below.
Calling module 30, for calling packed data statistical form, wherein, preserves the one-to-one relationship between data format, compressed configuration and compression effectiveness information in packed data statistical form;
Preferably, above-mentioned compressed configuration comprises: compression algorithm and compression parameters; Above-mentioned compression effectiveness information comprises: compression time and compressed data packets size.In actual applications, compression algorithm comprises: the cab compression algorithm etc. of the zip compression algorithm that the rar compression algorithm that compressed data packets is rar form, compressed data packets are zip form, compressed data packets to be the 7z compression algorithm of 7z form and compressed data packets be cab form.Compression parameters comprises: whether encrypt, solid (Solid) compression parameters and compression after whether delete the parameters such as source file.
In actual applications, packed data statistical form be in a large amount of experiments to various different file format (namely, above-mentioned data format) performance under different compression algorithms carries out adding up obtaining, in packed data statistical form, comprise the statistics of different compressed configuration in speed (calculating of speed carries out under same hardware environment) and compression ratio two, during for compressing file, the most suitable compressed configuration of Intelligent Matching provides foundation, thus reaches fastest or the object of compression ratio minimum (after compression, volume is minimum).It should be noted that, in embodiments of the present invention, the computational methods of compression ratio are: compression ratio=compressed data packets size/size of data to be compressed.As shown in table 1 according to the packed data statistical form of the embodiment of the present invention:
Table 1
Data format (counts before compression |
Compressed configuration |
Compression time |
Compressed data packets size |
Be 10M according to size) |
|
|
|
.gif |
Rar compression algorithm |
5s |
7M |
.gif |
Zip compression algorithm |
2s |
9M |
…… |
…… |
…… |
…… |
.txt |
Rar compression algorithm |
4s |
7.5M |
…… |
…… |
…… |
…… |
It should be noted that, each data in table 1 are only and illustrate, are not the actual experimental data recorded.
Select module 32, compact model for selecting according to data format and the user of data to be compressed obtains corresponding compression effectiveness information from packed data statistical form, and the compressed configuration corresponding with compact model according to compression effectiveness Information Selection, wherein, compact model comprises: compression speed mode of priority and compression volume mode of priority;
When user select compact model be compression speed mode of priority, select module 32 specifically for:
1, obtain the data format of data to be compressed, such as, data format is .gif;
2, from packed data statistical form, obtain the compression time of this data format under different compressed configuration, such as, as shown in table 1, when data format is .gif, under rar compression algorithm, compression time is 5s, and under zip compression algorithm, compression time is 2s; In actual applications, statistics in packed data statistical form is all compress the statistics that data that front size is 1M carry out for benchmark, but, when carrying out data compression, the size needing the data of compression is indefinite, in actual applications, only can be as the criterion with the compression time added up in packed data statistical form and compare, also the anticipated compression deadline of current data to be compressed can be calculated according to volume ratio, and with this anticipated compression deadline for benchmark compares.
3, obtain the fastest compressed configuration of compression speed according to compression time, such as, when data format is .gif, the compression time obtained from table 1 is respectively 5s and 2s, the zip compression algorithm of compressed configuration corresponding to 2s that compression speed is the fastest.
By above-mentioned process, user can be helped to select optimum compressed configuration intelligently thus realize the fastest object of compression speed.
In embodiments of the present invention, compression speed mode of priority is not give no thought to compressing file rate, but calculates under the prerequisite being standard with compress mode, under the prerequisite that sacrifice compression ratio is not very large, obtain the fastest speed.Be implemented as follows:
Experimentally add up, for the data to be compressed of most of form, what compression speed was the fastest is zip compression algorithm, and for a part by the data such as picture, audio-video document, document compressed, then compression ratio when compressing is very high, when the high threshold value to pre-setting of compression ratio (such as, threshold value is 98%) time, intelligence can skip these file types under compression speed mode of priority, that is, above-mentioned file not compressed.
Preferably, the device according to the embodiment of the present invention also comprises: filtering module and memory module, particularly:
Filtering module, compact model for selecting when user is compression speed mode of priority, before calling module 30 calls packed data statistical form, first according to the data format of data to be compressed, treat packed data to filter, filter out by compressed data (such as, by the data such as picture, audio-video document, document compressed), obtain not by compressed data.Subsequently, to the treatment step not performed calling module 30 by compressed data to be compressed obtained.Such as: filtering module automatically skips the file (or skipping compressed alternative document) of rmvb form, alternative document is adopted to the zip compression algorithm of standard.
Memory module, for treating after packed data compresses at compression module 34, by being directly stored in compressed data packets by compressed data of filtering out.
When user select compact model be compression volume mode of priority, select module 32 specifically for:
1, the data format of data to be compressed is obtained; Such as, data format is .gif;
2, from packed data statistical form, obtain the compressed data packets size of data format under different compressed configuration; Such as, as shown in table 1, when data format is .gif, under rar compression algorithm, compressed data packets size is 7M, and under zip compression algorithm, compressed data packets size is 9M; In actual applications, statistics in packed data statistical form is all compress data that front size is 1M to be as the criterion the statistics of carrying out, but, when carrying out data compression, the size of data to be compressed is indefinite, in actual applications, can only with the compressed data packets size of adding up in packed data statistical form for benchmark compares, also the anticipated compression data package size of current data to be compressed can be calculated according to volume ratio, and with this anticipated compression data package size for benchmark compares.
3, according to the compressed configuration that compressed data packets acquiring size compressed data packets volume is minimum.Such as, the compressed data packets size obtained from table 1 is respectively 7M and 9M, the rar compression algorithm of compressed configuration corresponding to 7M that compressed data packets is minimum.
It should be noted that, experimentally add up, solid compression parameters can allow compression ratio lower, therefore, the experiment statistics in packed data statistical form be all the data of solid compression.And for most of formatted file, what compression ratio was the highest is all 7z form, and only have the file types such as indivedual picture, audio-video document, document, the compression ratio of rar form is even better.Such as, the technical scheme of the embodiment of the present invention uses rar compression algorithm for data types such as indivedual picture, audio-video document, documents, and configure solid compression parameters and compress, 7z compression algorithm is adopted to alternative document, and configures solid compression parameters and compress.
By above-mentioned process, user can be helped to select optimum compressed configuration intelligently thus realize the minimum object of compressed data packets.
Preferably, in embodiments of the present invention, custom block can also be comprised, for determining compressed configuration according to manually arranging of user.
Compression module 34, for compressing data according to compressed configuration, obtains compressed data packets.
It should be noted that, data to be compressed can comprise the data of one or more different data format, therefore, in actual applications, module 32 is selected to need from packed data statistical form, obtain the compressed configuration corresponding respectively with each data format in data to be compressed, when data to be compressed are compressed, compression module 34 needs the compressed configuration corresponding according to each different data format to treat the data of each different data format in packed data to compress respectively, obtains compressed data packets.
In sum, by means of the technical scheme of the embodiment of the present invention, the compressed configuration data to user corresponding with the compact model that user selects by the Intelligent Matching when compressed file are compressed, solving user in prior art can not according to the problem needing to select suitable compression algorithm of oneself owing to lacking professional knowledge, the technical scheme of the embodiment of the present invention can according to the needs of user, automatically for user mates most suitable compressed configuration, thus reaching the object that compression speed is the fastest or compression volume is minimum, the use sense that improve user is subject to.
Although be example object, disclose the preferred embodiments of the present invention, it is also possible for those skilled in the art will recognize various improvement, increase and replacement, and therefore, scope of the present invention should be not limited to above-described embodiment.