CN-121996323-A - Applet file compression method, applet file reading method and electronic device
Abstract
The embodiment of the invention provides an applet file compression method, an applet file reading method and electronic equipment, and relates to the technical field of file processing. The method comprises the steps of obtaining an applet file set to be compressed, carrying out static code analysis on the applet file set, determining the file loading sequence of each original file in the applet file set, carrying out compression processing on the applet file set according to the file loading sequence to obtain a compressed package file, recording the storage offset and the compressed size of compressed data corresponding to each original file in the compressed package file, generating complete metadata based on each storage offset, each compressed size and the original attribute of each original file, writing the complete metadata into the compressed package file to obtain a complete compressed package of the applet file set, and thus improving the starting and loading speed of the applet.
Inventors
- CHEN HUIJUN
- DENG YUCHENG
- ZHANG SHUTING
Assignees
- 深圳凡泰极客科技有限责任公司
Dates
- Publication Date
- 20260508
- Application Date
- 20260121
Claims (10)
- 1. A method of applet file compression comprising: Acquiring an applet file set to be compressed; performing static code analysis on the applet file set to determine the file loading sequence of each original file in the applet file set; Compressing the applet file set according to the file loading sequence to obtain a compressed package file, and recording the storage offset and the compressed size of the compressed data corresponding to each original file in the compressed package file, wherein the compressed package file comprises a plurality of compressed frames, and the compressed data consists of one or more compressed frames corresponding to the original file; Generating complete metadata based on the storage offsets, the compressed sizes and the original attributes of the original files; and writing the complete metadata into the compressed package file to obtain a complete compressed package of the applet file set.
- 2. The method of claim 1, wherein the performing static code analysis on the applet file collection to determine a file loading order of the applet file collection comprises: Analyzing an entry configuration file in the applet file set to obtain an initial page path; Analyzing the initial page and each level code file referenced by the initial page based on a static code analysis technology, and constructing a dependency relationship among files; And according to the dependency relationship and the page loading priority, performing topological sorting, and determining the file loading sequence reflecting the loading sequence in actual running.
- 3. The method of claim 1, wherein the compressing the applet file set according to the file loading sequence to obtain a compressed package file, and recording a storage offset and a compressed size of compressed data corresponding to each original file in the compressed package file, includes: sequentially splicing a plurality of original files to be compressed into a combined data stream according to the file loading sequence; dividing the combined data stream into a plurality of data blocks according to a preset size; performing a compression operation on each of the data blocks to generate a compressed frame; Writing the generated compressed frames into a compressed package file; when the compressed frame corresponding to the original file is written into the compressed package file, the initial writing position of the first compressed frame corresponding to the original file is recorded and used as the storage offset; And after the writing of all the compressed frames corresponding to the original file is completed, calculating the compressed size according to the current writing position and the storage offset.
- 4. A method according to claim 3, wherein said performing a compression operation on each of said data blocks to generate a compressed frame comprises: for each data block, searching whether a data block with matched content exists in the compressed data blocks; If yes, generating a reference pointing to a corresponding compressed data block; if not, compressing the data block by using an entropy coding algorithm to generate a new compressed data block; Each of the compressed data blocks is combined into at least one compressed frame.
- 5. The method of claim 1, wherein generating complete metadata based on each of the stored offsets, each of the compressed sizes, and original attributes of each of the original files comprises: Generating basic metadata according to the original attributes of the original files, wherein the basic metadata at least comprises file paths and file names; And merging the basic metadata with the storage offset and the compressed size, and adding a compression mark and an encryption mark to generate complete metadata.
- 6. The method of claim 1, wherein said writing the complete metadata to the compressed package file to obtain a complete compressed package for the applet file set comprises: serializing the complete metadata into a metadata string; Encrypting the metadata character string to obtain an encrypted metadata character string; And writing the encryption metadata character string into the head of the compressed package file to obtain a complete compressed package of the applet file set.
- 7. The method according to any one of claims 1 to 6, wherein before the step of compressing the applet file set according to the file loading order to obtain a compressed package file and recording a storage offset and a compressed size of compressed data corresponding to each of the original files in the compressed package file, the method further comprises: determining a target file to be encrypted from each original file in the applet file set according to the file type; performing key expansion based on a preset master key and the target file to generate a plurality of round keys; Performing multiple rounds of iterative encryption operation on the target file by using the round keys, wherein the iterative encryption operation comprises round key exclusive OR and S box replacement; And carrying out reverse order transformation on the data after iterative encryption to obtain encrypted file data.
- 8. The method of any one of claims 1 to 6, wherein prior to the step of generating complete metadata based on each of the stored offsets, each of the compressed sizes, and the original attributes of each of the original files, the method further comprises: And for the original file which does not belong to the preset compressible type, directly writing the original data of the original file into the non-compressed section of the compressed package file.
- 9. An applet file reading method for reading a compressed package file generated by the applet file compression method according to any one of claims 1 to 8, characterized in that the method comprises: reading and analyzing the complete metadata in the compressed package file; Responding to a read request for a target original file, and determining the storage offset and the compressed size of the target original file in the compressed package file according to the complete metadata; reading corresponding compressed data from the compressed packet file according to the storage offset and the compressed size, wherein the compressed data consists of one or more compressed frames; and according to the compression mark and the encryption mark in the complete metadata, performing corresponding decompression and decryption processing on the compressed data to obtain the original data of the target original file.
- 10. An electronic device comprising a memory, a processor and a computer program stored on the memory and running on the processor, characterized in that the processor implements the method of any one of claims 1 to 9 when executing the computer program.
Description
Applet file compression method, applet file reading method and electronic device Technical Field The invention relates to the technical field of file processing, in particular to an applet file compression method, an applet file reading method and electronic equipment. Background With the development of the mobile internet, applets are widely used due to their feature of no installation, and ready-to-use. Typical applets are typically composed of a number of separate files, including, but not limited to, configuration files (e.g., app. Json) describing the program structure, script files (e.g., js) implementing business logic, files defining styles (e.g., css), and resource files for pictures, audio and video, etc. These files are organized in a directory structure that is parsed at run-time by the host APP load. Currently, in packaging distribution applets, common file compression and archiving formats (e.g., ZIP) are commonly employed to reduce network transport volumes. The core aim is to increase the compression rate or decompression speed, but under the specific application scene of the small program, the optimization consideration of the runtime performance is lacking, wherein the storage sequence of the file in the traditional compression package is generally irrelevant to the actual loading sequence, so that the small program needs to decompress the discontinuous data blocks frequently when starting, and the I/O overhead and the cold start delay are increased. Disclosure of Invention Accordingly, an object of the present invention is to provide an applet file compression method, an applet file reading method and an electronic device, which at least partially improve the above problems. In order to achieve the above object, the technical scheme adopted by the embodiment of the invention is as follows: in a first aspect, an embodiment of the present invention provides a method for compressing an applet file, including: Acquiring an applet file set to be compressed; performing static code analysis on the applet file set to determine the file loading sequence of each original file in the applet file set; Compressing the applet file set according to the file loading sequence to obtain a compressed package file, and recording the storage offset and the compressed size of the compressed data corresponding to each original file in the compressed package file, wherein the compressed package file comprises a plurality of compressed frames, and the compressed data consists of one or more compressed frames corresponding to the original file; Generating complete metadata based on the storage offsets, the compressed sizes and the original attributes of the original files; and writing the complete metadata into the compressed package file to obtain a complete compressed package of the applet file set. Optionally, the performing static code analysis on the applet file set to determine a file loading sequence of the applet file set includes: Analyzing an entry configuration file in the applet file set to obtain an initial page path; Analyzing the initial page and each level code file referenced by the initial page based on a static code analysis technology, and constructing a dependency relationship among files; And according to the dependency relationship and the page loading priority, performing topological sorting, and determining the file loading sequence reflecting the loading sequence in actual running. Optionally, the compressing the applet file set according to the file loading sequence to obtain a compressed package file, and recording a storage offset and a compressed size of compressed data corresponding to each original file in the compressed package file, including: sequentially splicing a plurality of original files to be compressed into a combined data stream according to the file loading sequence; dividing the combined data stream into a plurality of data blocks according to a preset size; performing a compression operation on each of the data blocks to generate a compressed frame; Writing the generated compressed frames into a compressed package file; when the compressed frame corresponding to the original file is written into the compressed package file, the initial writing position of the first compressed frame corresponding to the original file is recorded and used as the storage offset; And after the writing of all the compressed frames corresponding to the original file is completed, calculating the compressed size according to the current writing position and the storage offset. Optionally, the performing a compression operation on each of the data blocks to generate a compressed frame includes: for each data block, searching whether a data block with matched content exists in the compressed data blocks; If yes, generating a reference pointing to a corresponding compressed data block; if not, compressing the data block by using an entropy coding algorithm to generate a new compressed data bloc