File compression method, compressed file restoration method and storage medium
By performing differential processing on PDF files to generate decoded differential and encoded differential files, the problem of low compression rate of template files in existing technologies is solved, achieving efficient lossless compression and reduced storage space.
Patent Information
- Application Number
- CN202411137857.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-19
- Publication Date
- 2026-03-03
AI Technical Summary
Existing technologies have low compression rates when storing large numbers of PDF template files, resulting in high storage space consumption.
By performing differential processing on the target file and the template file, a decoded differential file and an encoded differential file are generated. Only the differences are recorded to generate a compressed file, and the target file is restored using the template file during restoration.
It improves the compression rate of template files, reduces storage space usage, and ensures lossless file compression and the validity of digital signatures.
Smart Images

Figure CN121597648A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a file compression method, a compressed file restoration method, and a storage medium. Background Technology
[0002] Currently, many business systems require the storage of a large number of Portable Document Format (PDF) template files (i.e., files containing a large amount of fixed content). Taking a contract management system as an example, the system needs to store a large number of PDF contract files. Most of the content of these contract files is the same, with only a small amount of content (such as the user information section) being different.
[0003] However, in the process of implementing this invention, it was found that the prior art has at least the following problems: When storing a large number of PDF template files, the prior art mostly stores them directly, which consumes a lot of storage space; in some scenarios, the template files can be compressed first based on existing compression algorithms, and then the compressed files can be stored, but the compression ratio of existing compression algorithms (i.e., the ratio of storage space saved after compression to storage space occupied before compression) is low, and the storage of compressed files still occupies a lot of storage space. Summary of the Invention
[0004] This invention provides a file compression method, a compressed file restoration method, and a storage medium, which can improve the compression rate of template files and reduce the storage space occupied when storing template files.
[0005] In a first aspect, embodiments of the present invention provide a file compression method, which may include: obtaining a target decoding file of a target file to be compressed, a secondary encoding file of the target decoding file, and a template decoding file of a template file; wherein the template file and the target file have overlapping segments; performing differential processing on the target decoding file and the template decoding file to obtain a decoded differential file, and performing differential processing on the target file and the secondary encoding file to obtain an encoded differential file; and generating a compressed file of the target file based on the decoded differential file and the encoded differential file.
[0006] Secondly, embodiments of the present invention provide a method for restoring a compressed file, wherein the compressed file is a file obtained according to the file compression method provided in the first aspect. The method includes: splitting the compressed file to obtain a decoded differential file and an encoded differential file; performing differential restoration processing on the decoded differential file based on the template decoded file of the template file to obtain a target decoded file of the compressed target file; performing secondary encoding processing on the target decoded file based on a predetermined encoding algorithm to obtain a secondary encoded file; and performing differential restoration processing on the encoded differential file based on the secondary encoded file to obtain the restored target file.
[0007] Thirdly, embodiments of the present invention also provide a file compression apparatus, which may include: an acquisition module, a processing module, and a compression module; specifically, the acquisition module is used to acquire a target decoding file of a target file to be compressed, a secondary encoding file of the target decoding file, and a template decoding file of a template file; wherein the template file and the target file have overlapping segments; the processing module is used to perform differential processing on the target decoding file and the template decoding file to obtain a decoded differential file, and to perform differential processing on the target file and the secondary encoding file to obtain an encoded differential file; the compression module is used to generate a compressed file of the target file based on the decoded differential file and the encoded differential file.
[0008] Fourthly, embodiments of the present invention also provide a device for restoring compressed files, wherein the compressed file is a file obtained according to the file compression method provided in the first aspect. The device includes: a splitting module, a processing module, and a restoration module; the splitting module is used to split the compressed file to obtain a decoded differential file and an encoded differential file; the processing module is used to perform differential restoration processing on the decoded differential file based on the template decoded file of the template file to obtain a target decoded file of the compressed target file; the processing module is further used to perform secondary encoding processing on the target decoded file based on a predetermined encoding algorithm to obtain a secondary encoded file; the restoration module is used to perform differential restoration processing on the encoded differential file based on the secondary encoded file to obtain the restored target file.
[0009] Fifthly, embodiments of the present invention provide an electronic device, the electronic device comprising:
[0010] One or more processors; a memory for storing one or more programs; when the one or more programs are executed by the one or more processors, the one or more processors implement the file compression method provided in any embodiment of the present invention, or implement the compressed file restoration method provided in any embodiment of the present invention.
[0011] In a sixth aspect, embodiments of the present invention also provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the file compression method as provided in any embodiment of the present invention, or implements the compressed file restoration method as provided in any embodiment of the present invention.
[0012] In a seventh aspect, embodiments of the present invention also provide a computer program product having a computer program stored thereon, which, when executed by a processor, implements the file compression method as provided in any embodiment of the present invention, or implements the compressed file restoration method as provided in any embodiment of the present invention.
[0013] The embodiments of the above invention have the following advantages or beneficial effects:
[0014] In the technical solution provided by this invention, considering that template files (i.e., the target files to be compressed in this invention) contain a large amount of fixed content, a general template file can be predetermined, which contains the same parts of different template files. When the target file needs to be compressed, the differences between the target file and the template file can be determined, and a compressed file of the target file can be generated based on these differences. In this way, the compressed file only records the content corresponding to the differences between the target file and the template file, and does not record the complete content of the target file. Therefore, the compression rate of template files can be improved, and the storage space occupied when storing template files can be reduced. In addition, the technical solution provided by this invention can be used to compress PDF template files. During the generation process of PDF files, the character stream, byte stream, cross-reference table, and metadata of the file are encoded and compressed. Therefore, the difference between the target file and the PDF template file after encoding and compression is large. If the differences between the target file and the template file are directly determined, the content of the differences will be extensive. Based on this, in this embodiment of the invention, when it is necessary to compress the target file, the target file can first be decoded to obtain a decoded file (i.e., the target decoded file in this embodiment of the invention). Then, the decoded file of the template file (i.e., the template decoded file in this embodiment of the invention) and the target decoded file are differentially processed to obtain a decoded differential file. A compressed file is then generated based on the decoded differential file. Correspondingly, when restoring the compressed file, the decoded differential file can be differentially restored based on the template decoded file to obtain the target decoded file. The target file can then be obtained from the target decoded file. Since the difference between the target decoded file and the template decoded file is not significant, the content of the decoded differential file will not be extensive. Furthermore, the encoding and decoding process of some file content is irreversible. For example, PDF template files generally contain a digital signature portion. The encoding and decoding process of this digital signature portion is irreversible (i.e., decoding the encoded digital signature portion cannot restore the original digital signature portion). Thus, when restoring the compressed file, encoding the target decoded file results in an encoded file that is not entirely identical to the original target file. Based on this, in this embodiment of the invention, during the compression of the target file, the secondary encoded file of the target decoded file and the target file can be differentially processed to obtain an encoded differential file. Then, a compressed file is obtained based on the encoded differential file and the decoded differential file. Afterwards, if it is necessary to restore the compressed file, the target file can be obtained by combining the encoded differential file and the decoded differential file. Specifically, the decoded differential file can be differentially restored based on the template decoded file to obtain the target decoded file. Then, the target decoded file can be secondary encoded to obtain a secondary encoded file. Finally, the encoded differential file can be differentially restored based on the secondary encoded file to obtain the target file.Since the target file to be restored is not obtained by directly encoding the target decoded file, but by differentially restoring the encoded differential file based on the secondary encoded file, it can be ensured that the restored target file is consistent with the target file before compression.
[0015] As can be seen, in the technical solution provided by the embodiments of the present invention, a decoded differential file is obtained by differential processing the target decoding file and the template decoding file, and an encoded differential file is obtained by differential processing the target file and the secondary encoded file. This can improve the compression ratio of template files, reduce the storage space occupied when storing template files, and ensure lossless compression of files (i.e., the target file obtained by restoring the compressed file is consistent with the target file before compression). For template files containing digital signatures, it can be ensured that the digital signature is not destroyed. Attached Figure Description
[0016] Figure 1 This is a schematic flowchart of a file compression method provided in an embodiment of the present invention;
[0017] Figure 2 This is a flowchart illustrating another file compression method provided in an embodiment of the present invention;
[0018] Figure 3 This is a schematic diagram illustrating the principle of a differential processing procedure provided in an embodiment of the present invention;
[0019] Figure 4 This is a flowchart illustrating a method for restoring compressed files according to an embodiment of the present invention;
[0020] Figure 5 This is a simplified flowchart illustrating a file compression method provided in an embodiment of the present invention;
[0021] Figure 6 This is a simplified flowchart illustrating a method for restoring compressed files provided in an embodiment of the present invention;
[0022] Figure 7 This is a schematic diagram of the structure of a file compression device provided in an embodiment of the present invention;
[0023] Figure 8 This is a schematic diagram of the structure of a compressed file restoration device provided in an embodiment of the present invention;
[0024] Figure 9 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0025] The present invention will now be described in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and not intended to limit it. Furthermore, it should be noted that, for ease of description, the accompanying drawings show only the parts relevant to the present invention, and not all of the structures.
[0026] In this article, the term "and / or" is merely a description of the relationship between related objects, indicating that there can be three relationships. For example, A and / or B can represent three situations: A exists alone, A and B exist simultaneously, and B exists alone.
[0027] Furthermore, the terms "comprising" and "having," and any variations thereof, used in the description of the embodiments of the present invention are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the steps or units listed, but may optionally include other steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or devices.
[0028] It should be noted that in the embodiments of the present invention, the terms "exemplary" or "for example" are used to indicate examples, illustrations, or explanations. Any embodiment or design scheme described as "exemplary" or "for example" in the embodiments of the present invention should not be construed as being more preferred or advantageous than other embodiments or design schemes. Specifically, the use of terms such as "exemplary" or "for example" is intended to present the relevant concepts in a specific manner. In the description of the embodiments of the present invention, unless otherwise stated, "multiple" or "each" means two or more.
[0029] Before describing the file compression method provided in the embodiments of the present invention in detail, the technical background of the embodiments of the present invention will be described in detail below.
[0030] Currently, many business systems require the storage of a large number of PDF files. In some application scenarios, these PDF files are template files. Template files have a fixed format and contain a large amount of fixed content. For different files under the same template format, most of the content is the same, with only a small amount differing. For example, in a contract management system, a large number of contract documents need to be stored. These contract documents are PDF template files, and each contract file contains two parts: a static part containing fixed content such as default contract terms and default fields in the signature area (e.g., signatory, signing date), and a dynamic part containing personalized content that users need to fill in (e.g., user information in the signature area). For different contract files under the same template format, the static part is the same, while the dynamic part differs.
[0031] In existing technologies, business systems require a large amount of storage space for storing a large number of PDF template files. Even when using conventional compression algorithms (such as zip, winrar, etc.) to compress these PDF template files, the compression ratio (i.e., the ratio of storage space saved after compression to storage space occupied before compression) is very low, which cannot effectively reduce the storage space occupied.
[0032] For example, if user A signs a contract document named zsan.pdf with a file size of 168KB (KB is a unit of measurement representing kilobytes), and user B signs another contract document in the same template format named lisi.pdf with a file size of 168KB, the two contract documents zsan.pdf and lisi.pdf are mostly the same, differing only in the user information section. Taking the zip algorithm as an example, there are currently two methods for compressing a large number of PDF template files. The first method is to package the files together and then compress them. For example, the two files zsan.pdf and lisi.pdf can be compressed together into zsanlisi.zip. The total size of the original files is 168KB + 168KB = 336KB, and the size of the compressed zip package is 276KB. The compression ratio is (336-276) / 336≈17.86%. The second method is to compress a single file. For example, zsan.pdf can be compressed into zsan.pdf.zip. The total size of the original files is 168KB, and the size of the compressed zip package is 138KB. The compression ratio is (168-138) / 168≈17.86%.
[0033] It is evident that the compression ratios of the two storage compression methods mentioned above are not high. Therefore, it is necessary to improve the existing compression methods for PDF template files to increase the compression ratio.
[0034] To address the problems existing in the prior art, the embodiments of the present invention improve the compression scheme for template files in the prior art. The improved compression scheme can improve the compression rate of template files, reduce the storage space occupied when storing template files, and ensure lossless compression.
[0035] Figure 1 This is a flowchart illustrating a file compression method provided in an embodiment of the present invention. This method is applicable to application scenarios requiring the compression of a large number of template files. The method can be executed by a file compression device provided in this embodiment of the invention, which can be implemented in software and / or hardware and integrated into an electronic device.
[0036] like Figure 1 As shown, the file compression method provided in this embodiment of the invention specifically includes the following steps:
[0037] S110. Obtain the target decoding file of the target file to be compressed, the secondary encoding file of the target decoding file, and the template decoding file of the template file.
[0038] Both the target file and the template file are template files, and they have overlapping sections (i.e., they are files under the same template format). In one possible implementation, the template file can be a pre-determined PDF file with a fixed template format, containing a large amount of fixed content and dynamic sections that require information to be filled in (e.g., user information). The target file to be compressed can be a PDF file obtained by filling in information in the template file. For example, the target file and the template file can be contract documents.
[0039] The target file is the target decoded file, which is the file obtained after decoding the target file; the template file is the template decoded file, which is the file obtained after decoding the template file.
[0040] PDF files are a mixture of character streams, byte streams, cross-reference tables, and metadata. Currently, during the generation of PDF files, a specified algorithm is generally used to encode and compress the PDF file. Specifically, character streams, byte streams, cross-reference tables, and metadata can be merged and compressed. Therefore, both the target file and the template file are encoded files. Although most of the content of the target file and the template file is the same, there are significant differences in the encoded data. The compression scheme provided in this embodiment of the invention needs to compare the target file and the template file to determine the differences during the compression process. If the differences between the target file and the template file generated by encoding and compression are directly determined, the content of the differences will be extensive, and the compression ratio will not be high when storing and compressing the differences. Therefore, in this embodiment of the invention, when compressing the target file, the target decoded file of the target file and the template decoded file of the template file can be obtained first. The differences between the target decoded file and the template decoded file are not significant, mainly reflected in the parts that need to be dynamically filled in the target file and the template file. In this way, during the compression process, the target decoded file and the template decoded file can be compared to determine the relatively small amount of difference, thereby improving the compression ratio.
[0041] Taking obtaining the target decoded file of a target file to be compressed as an example, during the generation of the target file, the character stream and byte stream in the target file are compressed. Therefore, the decoding process of the target file is essentially restoring the compressed character stream and byte stream. For instance, during the generation of the target file, the character stream and byte stream of the target file can be compressed using the deflate compression algorithm (a lossless compression algorithm). Specifically, compression can be performed first using the LZ77 algorithm (a dictionary-based, "sliding window" lossless compression algorithm), and then Huffman coding can be used to further compress the processed data to obtain the target file. Correspondingly, during the decoding process of the target file, the target file can be processed using the reverse processing of Huffman coding and the reverse processing of the LZ77 algorithm to obtain the target decoded file. Similarly, the template decoded file of a template file can be obtained.
[0042] After obtaining the target decoded file, it can be re-encoded to obtain a re-encoded version of the target decoded file. The encoding algorithm used in this re-encoding process is the same as the compression algorithm used during the generation of the target file. For example, if the character and byte streams of the target file were compressed using the deflate compression algorithm during generation, the same deflate compression algorithm can be used to compress the character and byte streams of the target decoded file to obtain the re-encoded version of the target decoded file.
[0043] It should be noted that during the file encoding process, some uncertain dynamic information (such as random numbers) may be added. Therefore, the secondary encoded file obtained by re-encoding the target file's decoded file is not necessarily identical to the target file. For example, PDF files support digital signature technology. Currently, many PDF files (such as contract documents) contain digital signatures. A digital signature can be a set of specific symbols or codes attached to the PDF file to represent the issuer's identity and the issuer's approval of the PDF file. The recipient can verify the digital signature to ensure that the PDF file has not been tampered with during transmission. Digital signatures have the same legal effect as paper signatures. For the digital signature portion, the encoding and decoding process is irreversible (i.e., decoding the encoded digital signature portion will not necessarily yield the same content as the original digital signature portion).
[0044] S120. Perform differential processing on the target decoding file and the template decoding file to obtain a decoded differential file, and perform differential processing on the target file and the secondary encoding file to obtain an encoded differential file.
[0045] After obtaining the target decoded file and the template decoded file, a differential algorithm can be used to compare them, determine the differences between them, and generate a decoding difference file relative to the template decoded file. This decoding difference file records the differences between the target decoded file and the template decoded file, as well as the positions of the common parts in the template decoded file. Based on this decoding difference file and the template decoded file, the target decoded file can be reconstructed.
[0046] Similarly, after obtaining the secondary encoded file of the target decoded file, a difference algorithm can be used to compare the secondary encoded file and the target file to determine the differences between the target file and the secondary encoded file. Based on these differences, a differential encoded file is generated. This differential encoded file records the differences between the secondary encoded file and the target file, as well as the positions of the identical parts in the secondary encoded file. Based on this differential encoded file and the secondary encoded file, the target file can be reconstructed.
[0047] In one possible implementation, both the template decoding file and the target decoding file include the same multiple objects. Among these objects, some objects in the template decoding file and the target decoding file have the same content, while others have different content. Taking a contract document as an example, both the template decoding file and the target decoding file include multiple objects such as contract terms, contract signatory headings, contract signatory signatures at the end, contract signing date, contract amount, and contract period. For each object, the specific content corresponding to the current object in the template decoding file can be compared with the specific content corresponding to the current object in the target decoding file. If they are the same, the current object is determined to be the same object (meaning the specific content corresponding to the current object is the same in both the target decoding file and the template decoding file); if they are different, the current object is determined to be a different object (meaning the specific content corresponding to the current object is different in both the target decoding file and the template decoding file). Then, a decoding difference file can be generated based on the object identifiers of the same objects, the object identifiers of the different objects, and the specific content of the different objects in the target decoding file. Similarly, an encoding difference file can be generated.
[0048] S130. Generate a compressed file of the target file based on the decoded differential file and the encoded differential file.
[0049] After obtaining the decoded and encoded differential files, they can be merged to obtain a compressed file of the target file. In practical applications, the decoded and encoded differential files can be embedded into a file with a custom format to obtain a merged file, which is the compressed file of the target file.
[0050] In the file compression method provided by this invention, considering that template files (i.e., the target files to be compressed in this invention) contain a large amount of fixed content, a general template file can be predetermined, which contains the same parts of different template files. When the target file needs to be compressed, the differences between the target file and the template file can be determined, and a compressed file of the target file can be generated based on these differences. In this way, the compressed file only records the content corresponding to the differences between the target file and the template file, and does not record the complete content of the target file. Therefore, the compression rate of template files can be improved, and the storage space occupied by template files can be reduced. In addition, the technical solution provided by this invention can be used to compress PDF template files. During the generation process of PDF files, the character stream, byte stream, cross-reference table, and metadata of the file are encoded and compressed. Therefore, the difference between the target file and the PDF template file after encoding and compression is large. If the differences between the target file and the template file are directly determined, the content of the differences will be extensive. Based on this, in this embodiment of the invention, when it is necessary to compress the target file, the target file can first be decoded to obtain a decoded file (i.e., the target decoded file in this embodiment of the invention). Then, the decoded file of the template file (i.e., the template decoded file in this embodiment of the invention) and the target decoded file are differentially processed to obtain a decoded differential file. A compressed file is then generated based on the decoded differential file. Correspondingly, when restoring the compressed file, the decoded differential file can be differentially restored based on the template decoded file to obtain the target decoded file. The target file can then be obtained from the target decoded file. Since the difference between the target decoded file and the template decoded file is not significant, the content of the decoded differential file will not be extensive. Furthermore, the encoding and decoding process of some file content is irreversible. For example, PDF template files generally contain a digital signature portion. The encoding and decoding process of this digital signature portion is irreversible (i.e., decoding the encoded digital signature portion cannot restore the original digital signature portion). Thus, when restoring the compressed file, encoding the target decoded file results in an encoded file that is not entirely identical to the original target file. Based on this, in this embodiment of the invention, during the compression of the target file, the secondary encoded file of the target decoded file and the target file can be differentially processed to obtain an encoded differential file. Then, a compressed file is obtained based on the encoded differential file and the decoded differential file. Afterwards, if it is necessary to restore the compressed file, the target file can be obtained by combining the encoded differential file and the decoded differential file. Specifically, the decoded differential file can be differentially restored based on the template decoded file to obtain the target decoded file. Then, the target decoded file can be secondary encoded to obtain a secondary encoded file. Finally, the encoded differential file can be differentially restored based on the secondary encoded file to obtain the target file.Since the target file to be restored is not obtained by directly encoding the target decoded file, but by differentially restoring the encoded differential file based on the secondary encoded file, it can be ensured that the restored target file is consistent with the target file before compression.
[0051] As can be seen, in the technical solution provided by the embodiments of the present invention, a decoded differential file is obtained by differential processing the target decoding file and the template decoding file, and an encoded differential file is obtained by differential processing the target file and the secondary encoding file. This can improve the compression ratio of template files, reduce the storage space occupied when storing template files, and ensure lossless compression of files (i.e., the target file obtained by restoring the compressed file is consistent with the target file before compression).
[0052] It should be noted that the file compression method provided in this embodiment of the invention can be applied to compressing template files of PDFs containing digital signatures as well as template files of PDFs that do not contain digital signatures. For template files of PDFs containing digital signatures, the validity of the digital signature can be ensured.
[0053] Reference Figure 2 This is a schematic flowchart illustrating another file compression method provided in an embodiment of the present invention. The method in this embodiment can be combined with various optional schemes in the file compression methods provided in the foregoing embodiments, further optimizing the file compression methods provided in the foregoing embodiments. Figure 2 As shown, the specific steps include:
[0054] S210. Obtain the target decoding file of the target file to be compressed, the secondary encoding file of the target decoding file, and the template decoding file of the template file.
[0055] Optionally, obtaining the target decoding file of the target file to be compressed, the secondary encoding file of the target decoding file, and the template decoding file of the template file includes: decoding the target file based on a predetermined decoding algorithm to obtain the target decoding file; performing secondary encoding on the target decoding file based on the encoding algorithm corresponding to the decoding algorithm to obtain the secondary encoding file; and determining the template decoding file corresponding to the template identifier from each candidate decoding file based on the template identifier corresponding to the target file.
[0056] For example, the decoding algorithm can be an algorithm corresponding to the deflate compression algorithm, that is, the reverse process of the deflate compression algorithm; the encoding algorithm can be the deflate compression algorithm.
[0057] A template identifier can be a string used to uniquely identify a template format. Template class files with the same template format have the same template identifier, while template class files with different template formats have different template identifiers. In one possible implementation, the template files corresponding to each frequently used template format in the current application scenario can be pre-determined, and then different template identifiers can be assigned to different template files. Next, each template file can be decoded to obtain its corresponding template decoding file (i.e., each candidate decoding file). The correspondence between each template file, its corresponding template identifier, and its corresponding template decoding file is then stored. When the target file needs to be compressed, the template decoding file corresponding to the target file's template identifier can be determined from the candidate decoding files based on this correspondence.
[0058] Taking the application scenario of storing contract documents as an example, we can obtain the template contract files corresponding to all the template formats frequently used in the contract management system in advance, and then decode these template contract files to obtain candidate decoded files. We can also store the correspondence between the template contract files, the template identifier of the template contract files, and the candidate decoded files.
[0059] In practical applications, it is necessary to store and compress a large number of template files with different template formats. If the corresponding template file is decoded every time a template file is stored and compressed, the compression efficiency will be very low. Therefore, in this embodiment of the invention, multiple template files with different template formats can be pre-determined, and the decoding results of each template file can be stored. In this way, when storing and compressing a batch of template files of the same format, only the template file of that format needs to be decoded once, which can improve the compression efficiency of batch template files.
[0060] Optionally, after determining the template decoding file corresponding to the template identifier from each candidate decoding file based on the template identifier corresponding to the target file, the file compression method provided in this embodiment of the invention further includes: if there is no template decoding file corresponding to the template identifier in each candidate decoding file, obtaining the template file and performing decoding processing on the template file based on the decoding algorithm to obtain the template decoding file.
[0061] In practical applications, as business systems change, new template files with different template formats may be generated. Therefore, it may be impossible to find a template decoding file corresponding to the template identifier of the target file among the candidate decoding files. Based on this, in this embodiment of the invention, if no template decoding file corresponding to the template identifier of the target file exists among the candidate decoding files, the template file corresponding to the target file can be determined to be a newly added file after the business system change. This newly added file is then decoded, and the decoding result is updated in the locally stored correspondence. It can be seen that the file compression method provided by this embodiment of the invention is applicable not only to static business systems but also to dynamically changing business systems, exhibiting wide adaptability and applicability to various business systems that require storing template files.
[0062] S220. Based on a predetermined binary differential algorithm, differential processing is performed on the target decoding file in binary format and the template decoding file in binary format to obtain a decoded differential file.
[0063] The binary differential algorithm compares the similarity between the target decoded file and the template decoded file in binary dimensions, finds the largest matching segment between the two files, and identifies the difference segments in the target decoded file that differ from the template decoded file. It then generates differential instructions, which are used to obtain the decoded differential file. When performing differential reconstruction on the decoded differential file in the compressed file, the differential instructions are converted into the target decoded file based on the template decoded file.
[0064] In one possible implementation, a differential tool supporting any binary differential algorithm can be used to perform differential processing on the target decoding file and the template decoding file in binary format to obtain a decoded differential file. Alternatively, a custom differential tool can be created based on a custom differential encoding standard, and then the target decoding file and the template decoding file in binary format can be differentially processed using the custom differential tool. For example, the differential encoding standard could be the RFC 3284 (a differential encoding standard) differential encoding format.
[0065] Optionally, based on a predetermined binary differential algorithm, differential processing is performed on the target decoding file in binary format and the template decoding file in binary format to obtain a decoded differential file, including: comparing characters of the target decoding file in binary format and the template decoding file in binary format based on the binary differential algorithm to obtain each target differential instruction of the target decoding file relative to the template decoding file; and generating a decoded differential file based on each target differential instruction.
[0066] The target difference instructions are arranged in sequence, including copy-type target difference instructions and assignment-type target difference instructions. Copy-type instructions include a difference position field and a number of elements in the segment to be inserted field, while assignment-type instructions include a field to be assigned and a number of elements field. The difference position field is used to characterize the position of the segment to be inserted in the binary format template decoding file.
[0067] In one possible implementation, during the process of restoring the target decoded file based on each target differential instruction, the first target differential instruction can be determined from the target differential instructions based on their order. If the instruction type of the first target differential instruction is copy, a copy position can be determined in the binary format template decoded file based on the differential position field in the first target differential instruction. Then, starting from this copy position, multiple consecutive elements (the number of elements is equal to the number of elements in the first target differential instruction) are found in the binary format template decoded file, and the fragments corresponding to these multiple elements are inserted into an empty queue. If the instruction type of the first target differential instruction is assignment, it can be first determined whether the instruction is used to assign values to the same element or to different elements. If it is used to assign values to the same element, the same element is assigned multiple times (the number of assignments is equal to the number of elements in the first target differential instruction) to obtain the fragment to be inserted. If it is used to assign values to different elements, the fragment to be inserted is obtained directly based on the assignment field. After determining the fragment to be inserted, it is inserted into an empty queue. Next, the second target differential instruction can be determined from the target differential instructions. This second instruction is then processed in a similar manner to the first, yielding the second segment to be inserted. This second segment is then inserted after the first segment to be inserted in the queue. Similarly, the remaining target differential instructions can be processed until the last one is processed. The resulting queue can then be identified as the target decoded file to be restored.
[0068] Reference Figure 3 This is a schematic diagram illustrating the principle of a differential processing procedure provided in an embodiment of the present invention. Figure 3 As shown, the upper part can be a template decoding file (hereinafter referred to as file A) containing 26 characters in binary format, and the lower part can be a target decoding file (hereinafter referred to as file B) containing 28 characters in binary format. After performing differential processing on file A and file B based on the binary differential algorithm, the following can be obtained: Figure 3 The six differential instructions are shown in sequence. Figure 3As shown, the first difference instruction is "COPY4, 0", the second difference instruction is "ADD4, wxyz", the third difference instruction is "COPY4, 4", the fourth difference instruction is "COPY8, 34", the fifth difference instruction is "RUN4, z", and the sixth difference instruction is "COPY4, 22". Specifically, "COPY4, 0" is a copy instruction, indicating that starting from position "0" in file A, four characters are copied consecutively to obtain the first segment of file B; "ADD4, wxyz" is an assignment instruction, indicating that the four characters "wxyz" will be used to obtain the second segment of file B; "COPY4, 4" is a copy instruction, indicating that starting from position "4" in file A, four characters are copied consecutively to obtain the third segment of file B; "COPY8, 34"... The first instruction is a copy instruction. Since 34 is greater than the length of file A (26), 34 minus 26 equals 8. Then, starting from position "8" in file B, 8 characters are copied consecutively to obtain the fourth segment of file B. The second instruction is an assignment instruction. It means that the character "z" is assigned 4 times to obtain the fifth segment of file B. The third instruction is a copy instruction. It means that starting from position "22" in file A, 4 characters are copied consecutively to obtain the sixth segment of file B.
[0069] In this embodiment of the invention, when performing differential processing on two files based on a binary differential algorithm, differential instructions can be generated to represent the relationship between the two files. In this way, the differences and similarities between the two files can be marked accurately and quickly, thereby further improving the compression processing efficiency and compression accuracy.
[0070] Optionally, based on a binary differential algorithm, a character comparison is performed between the target decoding file in binary format and the template decoding file in binary format to obtain each target differential instruction of the target decoding file relative to the template decoding file. This includes: determining whether there is a target template differential instruction group corresponding to the target file in each template differential instruction group; and, if it is determined that there is no target template differential instruction group in each template differential instruction group, performing a character comparison between the target decoding file in binary format and the template decoding file in binary format based on a binary differential algorithm to obtain each target differential instruction.
[0071] Among them, for each template differential instruction group, the current template differential instruction group can be obtained by pre-processing the decoded file of a file to be compressed in the current template format and the template decoded file.
[0072] In practical applications, it is necessary to compress batches of template files with the same template format. This requires determining the differential instruction groups of different target decoded files with the same template format relative to the template decoded file. Since most of the content of different target decoded files with the same template format is identical, most of the differential instructions in the differential instruction groups of different target decoded files with the same template format relative to the template decoded file are the same; for example, copying instructions are identical. Based on this, in this embodiment of the invention, differential instruction groups (i.e., each template differential instruction group) for different template formats can be predetermined. When performing differential processing on binary format target decoded files and binary format template decoded files, if each template differential instruction group includes a target template differential instruction group corresponding to the template format of the target decoded file, then each target differential instruction can be determined by referring to that target template differential instruction group. This eliminates the need to compare the characters of the two files one by one, thereby further improving compression efficiency.
[0073] Optionally, after determining whether a target template differential instruction group corresponding to the target file exists in each template differential instruction group, the file compression method provided in this embodiment of the invention further includes: when it is determined that a target template differential instruction group exists in each template differential instruction group, determining the difference segment corresponding to the assignment type template differential instruction in the binary format target decoding file based on the sorting position of the assignment type template differential instruction in the target template differential instruction group, determining the assignment type differential instruction corresponding to the assignment type template differential instruction based on the difference segment, and determining the sorting position of the assignment type differential instruction based on the sorting position of the assignment type template differential instruction; determining each target differential instruction based on the assignment type differential instruction, the sorting position of the assignment type differential instruction, the copy type template differential instruction in the target template differential instruction group, and the sorting position of the copy type template differential instruction.
[0074] For different target files with the same template format, all copy-type differential instructions in their corresponding differential instruction groups are identical, with only a few assignment-type instructions differing. Based on this, in this embodiment of the invention, when performing differential processing on a binary format target decoding file and a binary format template decoding file, the target template differential instruction group corresponding to the target decoding file can be determined first. Then, based on the instruction type of the differential instructions in the target template differential instruction group, the target differential instructions of the target decoding file can be quickly obtained. Specifically, the copy-type differential instructions can remain unchanged; only the assignment-type differential instructions need to be re-determined. This further improves compression processing efficiency.
[0075] S230. Based on the binary differential algorithm, differential processing is performed on the target file in binary format and the secondary encoded file in binary format to obtain the encoded differential file.
[0076] The method for determining the encoded differential file is the same as the method for determining the decoded differential file, and can be referred to the foregoing relevant descriptions. The embodiments of the present invention will not be repeated here.
[0077] It should be noted that the order of steps S220 and S230 is not limited in the embodiments of the present invention. In practical applications, step S230 may also be executed before step S220.
[0078] S240. Generate a compressed file of the target file based on the decoded differential file and the encoded differential file.
[0079] In this embodiment of the invention, based on the aforementioned embodiments, considering that the target decoding file, template decoding file, target file, and secondary encoded file are actually stored in binary form in the computer, and that the binary differential algorithm has the following advantages: strong anti-interference capability, long transmission distance, high data transmission rate, and low error rate, the data can be processed in a binary dimension when performing differential processing on the target decoding file and template decoding file, and on the target file and secondary encoded file. Processing data in a binary dimension does not involve processing the file content itself, but rather processing binary data, which further ensures that the resulting compressed file is a lossless file (i.e., achieving binary lossless compression). Specifically, for a PDF file, if the compressed file has the same content as the original file but a different binary format, then the compression process is not binary lossless compression.
[0080] It should be noted that the file compression methods proposed in the embodiments of the present invention and the foregoing embodiments belong to the same inventive concept. Technical details not described in detail in this embodiment can be found in the foregoing embodiments, and the beneficial effects of the foregoing embodiments are also applicable in this embodiment.
[0081] Reference Figure 4 This is a flowchart illustrating a method for restoring compressed files according to an embodiment of the present invention. This method is applicable to scenarios involving the restoration of compressed files obtained using the file compression method provided in this embodiment. The method can be executed by a file restoration device provided in this embodiment, which can be implemented in software and / or hardware and integrated into an electronic device.
[0082] like Figure 4 As shown, the method for restoring compressed files provided in this embodiment of the invention specifically includes the following steps:
[0083] S410. Split the compressed file to obtain a decoded differential file and an encoded differential file.
[0084] During compression, the decoded differential file and the encoded differential file are merged into one file. When restoring the compressed file, the decoded differential file and the encoded differential file can be separated from the merged file.
[0085] S420. Based on the template file, the template decoding file performs differential restoration processing on the decoded differential file to obtain the target decoding file of the compressed target file.
[0086] The process of performing differential restoration on the decoded differential file based on the template decoded file can be the reverse of the differential processing process. For example, the template decoded file can be processed according to the target differential instructions in the decoded differential file to obtain the target decoded file. The specific differential restoration process can be referred to the relevant description of the compression process mentioned above, and will not be repeated here in the embodiments of the present invention.
[0087] S430. The target decoding file is subjected to secondary encoding processing based on a predetermined encoding algorithm to obtain a secondary encoded file.
[0088] S440. Perform differential restoration processing on the encoded differential file based on the secondary encoded file to obtain the restored target file.
[0089] The method for determining the restored target file is similar to the method for determining the target decoded file of the compressed target file, and will not be described again in this embodiment of the invention.
[0090] It should be noted that the method for restoring compressed files provided in this embodiment of the invention belongs to the same inventive concept as the file compression method proposed in the foregoing embodiments. Technical details not described in detail in this embodiment can be found in the foregoing embodiments, and the beneficial effects of the foregoing embodiments are also applicable in this embodiment.
[0091] To more clearly describe the file compression method provided in the embodiments of the present invention, a specific example is given below. (Refer to...) Figure 5 This is a simplified flowchart illustrating a file compression method provided in an embodiment of the present invention. Figure 5As shown, when compressing the target file lisi.pdf, it can first be decoded to obtain the target decoded file lisi_decd.pdf; and the decoded file of the template file zsan.pdf, i.e., the template decoded file zsan_tpl.pdf, can also be obtained. For template files of the same template format, only one decoding process is required. Then, binary difference can be performed on the target decoded file lisi_decd.pdf and the template decoded file zsan_tpl.pdf to obtain the decoded difference file lisi_decd.dif. Furthermore, the target decoded file lisi_decd.pdf can be re-encoded to obtain the re-encoded file lisi_encd.pdf, and binary difference can be performed on the re-encoded file lisi_encd.pdf and the target file lisi.pdf to obtain the encoded difference file lisi_encd.dif. Finally, the encoded difference file lisi_encd.dif and the decoded difference file lisi_decd.dif can be merged to obtain the compressed file lisi.pdf.dif.
[0092] Similarly, to more clearly describe the method for restoring compressed files provided in the embodiments of the present invention, a specific example is given below. (Refer to...) Figure 6 This is a simplified flowchart illustrating a method for restoring compressed files according to an embodiment of the present invention. Figure 6 As shown, when it is necessary to restore the compressed file lisi.pdf.dif, the decoded differential file lisi_decd.dif can be differentially restored using the template decoding file zsan_tpl.pdf to obtain the target decoded file lisi_decd.pdf. Then, the target decoded file lisi_decd.pdf can be re-encoded to obtain the re-encoded file lisi_encd.pdf. After that, the encoded differential file lisi_encd.dif can be differentially restored using the re-encoded file lisi_encd.pdf to obtain the target file lisi.pdf.
[0093] Figure 7 This is a schematic diagram of the structure of a file compression device provided in an embodiment of the present invention. The device includes: an acquisition module 710, a processing module 720, and a compression module 730.
[0094] For example, the acquisition module 710 can execute S110 in the above method embodiment, the processing module 720 can execute S120 in the above method embodiment, and the compression module 730 can execute S130 in the above method embodiment.
[0095] Specifically, the acquisition module 710 is used to acquire the target decoded file of the target file to be compressed, the secondary encoded file of the target decoded file, and the template decoded file of the template file; wherein the template file and the target file have overlapping segments; the processing module 720 is used to perform differential processing on the target decoded file and the template decoded file to obtain a decoded differential file, and to perform differential processing on the target file and the secondary encoded file to obtain an encoded differential file; the compression module 730 is used to generate a compressed file of the target file based on the decoded differential file and the encoded differential file.
[0096] Optionally, in one possible implementation, the processing module 720 is specifically used to: perform differential processing on the target decoding file in binary format and the template decoding file in binary format based on a predetermined binary differential algorithm to obtain a decoded differential file; and perform differential processing on the target file in binary format and the secondary encoding file in binary format based on the binary differential algorithm to obtain an encoded differential file.
[0097] Optionally, in another possible implementation, the processing module 720 is further specifically used for:
[0098] Based on the binary differential algorithm, a character comparison is performed between the target decoding file and the template decoding file in binary format to obtain the target differential instructions of the target decoding file relative to the template decoding file. The target differential instructions are arranged in sequence, including copy-type target differential instructions and assignment-type target differential instructions. The copy-type instructions include a differential position field and an element count field of the segment to be inserted, while the assignment-type instructions include an assignment field and an element count field. The differential position field is used to characterize the position of the segment to be inserted in the template decoding file in binary format. A decoded differential file is generated based on each target differential instruction.
[0099] Optionally, in another possible implementation, the processing module 720 is further specifically used for:
[0100] Determine whether there is a target template difference instruction group in each template difference instruction group that corresponds to the target file;
[0101] If it is determined that there is no target template differential instruction group in each template differential instruction group, the target decoding file in binary format and the template decoding file in binary format are compared character by character based on the binary differential algorithm to obtain each target differential instruction.
[0102] Optionally, in another possible implementation, the processing module 720 is further specifically used for:
[0103] After determining whether a target template differential instruction group corresponding to the target file exists in each template differential instruction group, and if a target template differential instruction group exists in each template differential instruction group, the difference segment corresponding to the assignment type template differential instruction is determined in the binary format target decoding file based on the sorting position of the assignment type template differential instruction in the target template differential instruction group. The assignment type differential instruction corresponding to the assignment type template differential instruction is determined based on the difference segment, and the sorting position of the assignment type differential instruction is determined based on the sorting position of the assignment type template differential instruction.
[0104] Based on the assignment-type differential instruction, the sorting position of the assignment-type differential instruction, the copy-type template differential instruction in the target template differential instruction group, and the sorting position of the copy-type template differential instruction, each target differential instruction is determined.
[0105] Optionally, in another possible implementation, the acquisition module 710 is specifically used for:
[0106] The target file is decoded based on a predetermined decoding algorithm to obtain a target decoded file; the target decoded file is then encoded a second time based on the encoding algorithm corresponding to the decoding algorithm to obtain a second encoded file; and the template decoded file corresponding to the template identifier is determined from each candidate decoded file based on the template identifier corresponding to the target file.
[0107] Optionally, in another possible implementation, the acquisition module 710 is further specifically used for:
[0108] If no template decoding file corresponding to the template identifier exists in any of the candidate decoding files, obtain the template file and decode it based on the decoding algorithm to obtain the template decoding file.
[0109] The file compression device provided in this embodiment of the invention belongs to the same inventive concept as the file compression methods provided in the foregoing embodiments. For details not described in detail in the embodiments of the file compression device, please refer to the relevant content of the foregoing method embodiments. The corresponding beneficial effects can also be referred to the beneficial effect analysis of the foregoing method embodiments.
[0110] Figure 8 This is a schematic diagram of the structure of a compressed file restoration device provided in an embodiment of the present invention. The compressed file is a file obtained by the file compression method provided in an embodiment of the present invention. The device includes: a splitting module 810, a processing module 820, and a restoration module 830.
[0111] For example, the splitting module 810 can execute S410 in the above method embodiment, the processing module 820 can execute S420 and S430 in the above method embodiment, and the restoration module 830 can execute S440 in the above method embodiment.
[0112] Specifically, the splitting module 810 is used to split the compressed file to obtain a decoded differential file and an encoded differential file; the processing module 820 is used to perform differential restoration processing on the decoded differential file based on the template decoded file of the template file to obtain the target decoded file of the compressed target file; the processing module 820 is also used to perform secondary encoding processing on the target decoded file based on a predetermined encoding algorithm to obtain a secondary encoded file; the restoration module 830 is used to perform differential restoration processing on the encoded differential file based on the secondary encoded file to obtain the restored target file.
[0113] The compressed file restoration device provided in this embodiment of the invention belongs to the same inventive concept as the file compression method provided in the foregoing embodiments. Details not described in detail in this embodiment can be referred to the relevant content of the foregoing method embodiments, and the corresponding beneficial effects can also be referred to the beneficial effect analysis of the foregoing method embodiments.
[0114] Figure 9 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Figure 9 A block diagram is shown of an exemplary electronic device 12 suitable for implementing embodiments of the present invention. Figure 9 The electronic device 12 shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of the present invention.
[0115] like Figure 9 As shown, the electronic device 12 is represented in the form of a general-purpose computing device. The components of the electronic device 12 may include, but are not limited to: one or more processors or processing units 16, system memory 28, and bus 18 connecting different system components (including system memory 28 and processing unit 16).
[0116] Bus 18 represents one or more of several bus architectures, including a memory bus or memory controller, a peripheral bus, a graphics acceleration port, a processor, or a local bus using any of the various bus architectures. For example, these architectures include, but are not limited to, the Industry Standard Architecture (ISA) bus, the Micro Channel Architecture (MAC) bus, the Enhanced ISA bus, the Video Electronics Standards Association (VESA) local bus, and the Peripheral Component Interconnect (PCI) bus.
[0117] Electronic device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by electronic device 12, including volatile and non-volatile media, removable and non-removable media.
[0118] System memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory (i.e., Figure 9 (The cache in the memory). Electronic device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, storage system 34 may be used to read and write non-removable, non-volatile magnetic media ( Figure 9 Not shown; usually referred to as a "hard drive"). Although Figure 9 Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk") and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 18 via one or more data media interfaces. System memory 28 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of the embodiments of the present invention.
[0119] A program / utility 40 having a set (at least one) of program modules 42 may be stored, for example, in system memory 28. Such program modules 42 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment. Program modules 42 typically perform the functions and / or methods described in the embodiments of the present invention.
[0120] Electronic device 12 can also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, etc.), and with one or more devices that enable a user to interact with the electronic device 12, and / or with any device that enables the electronic device 12 to communicate with one or more other computing devices (e.g., network card, modem, etc.). This communication can be performed through input / output (I / O) interface 22. Furthermore, electronic device 12 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via network adapter 20. Figure 9 As shown, network adapter 20 communicates with other modules of electronic device 12 via bus 18. It should be understood that, although... Figure 9As not shown, other hardware and / or software modules may be used in conjunction with electronic device 12, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0121] The processing unit 16 executes various functional applications and data processing by running programs stored in the system memory 28, such as implementing the steps of the file compression method provided in any of the foregoing embodiments of the present invention. The method includes: obtaining a target decoding file of the target file to be compressed, a secondary encoding file of the target decoding file, and a template decoding file of the template file; wherein the template file and the target file have overlapping segments; performing differential processing on the target decoding file and the template decoding file to obtain a decoded differential file, and performing differential processing on the target file and the secondary encoding file to obtain an encoded differential file; and generating a compressed file of the target file based on the decoded differential file and the encoded differential file.
[0122] Of course, those skilled in the art will understand that the processor can also implement the technical solutions of the file compression method provided in any embodiment of the present invention.
[0123] This embodiment provides a computer-readable storage medium storing a computer program thereon. When executed by a processor, the program implements the steps of the file compression method provided in any of the foregoing embodiments of the present invention. The method includes: obtaining a target decoding file of a target file to be compressed, a secondary encoding file of the target decoding file, and a template decoding file of a template file; wherein the template file and the target file have overlapping segments; performing differential processing on the target decoding file and the template decoding file to obtain a decoded differential file, and performing differential processing on the target file and the secondary encoding file to obtain an encoded differential file; and generating a compressed file of the target file based on the decoded differential file and the encoded differential file.
[0124] The computer storage medium of this invention can be any combination of one or more computer-readable media. A computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. For example, a computer-readable storage medium can be, but is not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0125] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, capable of sending, propagating, or transmitting programs for use by or in connection with an instruction execution system, apparatus, or device.
[0126] Program code contained on a computer-readable medium may be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.
[0127] Computer program code for performing the operations of this invention can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, as well as conventional procedural programming languages such as "C" or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or electronic device. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0128] This embodiment provides a computer program product on which a computer program is stored. When the program is executed by a processor, it implements the steps of the file compression method provided in any of the foregoing embodiments of the present invention.
[0129] Those skilled in the art will understand that the modules or steps of the present invention described above can be implemented using general-purpose computing devices. They can be centralized on a single computing device or distributed across a network of multiple computing devices. Optionally, they can be implemented using computer-executable program code, thereby allowing them to be stored in a storage device for execution by a computing device, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any particular combination of hardware and software.
[0130] Note that the above description is merely a preferred embodiment of the present invention and the technical principles employed. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and various obvious changes, readjustments, and substitutions can be made without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in detail through the above embodiments, the present invention is not limited to the above embodiments, and may include many other equivalent embodiments without departing from the concept of the present invention, the scope of which is determined by the scope of the appended claims.
Claims
1. A file compression method, characterized in that, include: Obtain the target decoded file of the target file to be compressed, the secondary encoded file of the target decoded file, and the template decoded file of the template file; wherein the template file and the target file have overlapping segments; Differential processing is performed on the target decoding file and the template decoding file to obtain a decoded differential file, and differential processing is performed on the target file and the secondary encoding file to obtain an encoded differential file; Based on the decoded differential file and the encoded differential file, a compressed file of the target file is generated.
2. The file compression method according to claim 1, characterized in that, The step of performing differential processing on the target decoding file and the template decoding file to obtain a decoded differential file, and performing differential processing on the target file and the secondary encoded file to obtain an encoded differential file, includes: Based on a predetermined binary differential algorithm, the target decoding file in binary format and the template decoding file in binary format are differentially processed to obtain the decoded differential file; Based on the binary differential algorithm, the target file in binary format and the secondary encoded file in binary format are differentially processed to obtain the encoded differential file.
3. The file compression method according to claim 2, characterized in that, The method of performing differential processing on the target decoding file in binary format and the template decoding file in binary format based on a predetermined binary differential algorithm to obtain the decoded differential file includes: Based on the binary differential algorithm, a character comparison is performed between the target decoding file in binary format and the template decoding file in binary format to obtain target differential instructions for the target decoding file relative to the template decoding file; wherein, the target differential instructions are arranged in sequence, including copy-type target differential instructions and assignment-type target differential instructions; the copy-type instructions include a differential position field and an element count field of the segment to be inserted, and the assignment-type instructions include an assignment field and the element count field, wherein the differential position field is used to characterize the position of the segment to be inserted in the template decoding file in binary format; The decoded differential file is generated based on the target differential instructions.
4. The file compression method according to claim 3, characterized in that, The step of comparing characters between the target decoded file (in binary format) and the template decoded file (in binary format) based on the binary differential algorithm to obtain target differential instructions of the target decoded file relative to the template decoded file includes: Determine whether there is a target template difference instruction group in each template difference instruction group that corresponds to the target file; If it is determined that the target template differential instruction group does not exist in any of the template differential instruction groups, the target decoding file in binary format and the template decoding file in binary format are compared character by character based on the binary differential algorithm to obtain the target differential instructions.
5. The file compression method according to claim 4, characterized in that, After determining whether there is a target template differential instruction group corresponding to the target file in each template differential instruction group, the method further includes: If it is determined that the target template differential instruction group exists in each of the template differential instruction groups, based on the sorting position of the assignment type template differential instructions in the target template differential instruction group, the difference segment corresponding to the assignment type template differential instruction is determined in the target decoding file in binary format, and the assignment type differential instruction corresponding to the assignment type template differential instruction is determined according to the difference segment, and the sorting position of the assignment type differential instruction is determined according to the sorting position of the assignment type template differential instruction; The target differential instruction is determined based on the assignment-type differential instruction, the sorting position of the assignment-type differential instruction, the copy-type template differential instruction in the target template differential instruction group, and the sorting position of the copy-type template differential instruction.
6. The file compression method according to claim 1, characterized in that, The process of obtaining the target decoding file of the target file to be compressed, the secondary encoding file of the target decoding file, and the template decoding file of the template file includes: The target file is decoded based on a predetermined decoding algorithm to obtain the target decoded file; Based on the encoding algorithm corresponding to the decoding algorithm, the target decoded file is subjected to secondary encoding processing to obtain the secondary encoded file; Based on the template identifier corresponding to the target file, the template decoding file corresponding to the template identifier is determined from each candidate decoding file.
7. The file compression method according to claim 6, characterized in that, After determining the template decoding file corresponding to the template identifier from each candidate decoding file based on the template identifier corresponding to the target file, the method further includes: If no template decoding file corresponding to the template identifier exists in any of the candidate decoding files, the template file is obtained, and the template file is decoded based on the decoding algorithm to obtain the template decoding file.
8. A method for restoring compressed files, characterized in that, The compressed file is a file obtained by the file compression method according to any one of claims 1-7, the method comprising: The compressed file is split to obtain a decoded differential file and an encoded differential file; Based on the template decoding file of the template file, the decoded differential file is subjected to differential restoration processing to obtain the target decoding file of the compressed target file; The target decoded file is subjected to secondary encoding processing based on a predetermined encoding algorithm to obtain a secondary encoded file; The differential encoding file is subjected to differential restoration processing based on the secondary encoded file to obtain the restored target file.
9. A file compression device, characterized in that, include: The acquisition module is used to acquire the target decoded file of the target file to be compressed, the secondary encoded file of the target decoded file, and the template decoded file of the template file; wherein the template file and the target file have overlapping segments; The processing module is used to perform differential processing on the target decoding file and the template decoding file to obtain a decoded differential file, and to perform differential processing on the target file and the secondary encoding file to obtain an encoded differential file; A compression module is used to generate a compressed file of the target file based on the decoded differential file and the encoded differential file.
10. A device for restoring compressed files, characterized in that, The compressed file is a file obtained by the file compression method according to any one of claims 1-7, and the apparatus includes: A splitting module is used to split the compressed file into decoded differential files and encoded differential files; The processing module is used to perform differential restoration processing on the decoded differential file based on the template decoding file of the template file to obtain the target decoded file of the compressed target file; The processing module is further configured to perform secondary encoding processing on the target decoded file based on a predetermined encoding algorithm to obtain a secondary encoded file; The restoration module is used to perform differential restoration processing on the encoded differential file based on the secondary encoded file to obtain the restored target file.
11. An electronic device, characterized in that, The electronic device includes: One or more processors; Memory, used to store one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the file compression method as described in any one of claims 1-7, or implement the compressed file restoration method as described in claim 8.
12. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the file compression method as described in any one of claims 1-7, or the file restoration method as described in claim 8.