Data compression method and device

By obtaining data category, importance and device status parameters, the target compression strategy and level are dynamically determined, which solves the problem of tight storage space, improves data storage and processing efficiency, and achieves a balance between quality and space.

CN120729327APending Publication Date: 2025-09-30SHANGHAI INNOVATECH INFORMATION TECH
View PDF 0 Cites 4 Cited by

Patent Information

Application Number
CN202510717477.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-30
Publication Date
2025-09-30

AI Technical Summary

Technical Problem

With the increase of multimedia content, the demand for storage space continues to grow. Especially on resource-constrained devices, the problem of tight storage space has gradually emerged, affecting the user's device experience.

Method used

By obtaining the category, importance and device status parameters of the data to be compressed, the target compression strategy and compression level are dynamically determined, and a highly adaptable compression method is adopted, including the selection of candidate compression strategies and the establishment of index information, to ensure a balance between data quality and storage space.

Benefits of technology

It improves data storage and processing efficiency, adapts to modern and changing equipment environments and data requirements, and ensures a good balance between data quality and storage space.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120729327A_ABST
    Figure CN120729327A_ABST
Patent Text Reader

Abstract

The invention provides a data compression method and device, and relates to the technical field of data processing and data compression. The method comprises the following steps: acquiring to-be-compressed data, and acquiring a data category of the to-be-compressed data; determining a plurality of candidate compression strategies corresponding to the to-be-compressed data based on the data category; the importance degree of the to-be-compressed data is obtained, and the equipment state parameter of the current equipment is obtained; determining a target compression strategy and a compression level corresponding to the target compression strategy from the candidate compression strategies based on the equipment state parameters and the importance; and executing the target compression strategy on the to-be-compressed data according to the compression level to obtain compressed data. According to the method, the target compression strategy can be dynamically determined according to the data type, the data importance and the equipment state, high flexibility and adaptability are achieved, the data storage and processing efficiency is improved, good balance between the data quality and the storage space is ensured, and the method adapts to modern changeable equipment environments and data requirements.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of data processing and data compression, and in particular to a data compression method and device thereof. Background Art

[0002] With the continuous development of mobile applications, especially the increase in multimedia content such as high-definition videos, audio files, images, and various application data, users' demand for storage space continues to grow. Although the storage capacity of devices such as smartphones and tablets continues to increase, it is still limited compared to the growing data demand. Especially on some resource-constrained devices, storage space is often restricted by physical hardware limitations, such as the capacity and memory of SD cards (Secure Digital Cards). In addition, as applications continue to become more complex, the amount of data generated is growing exponentially, and the problem of limited storage space has gradually become apparent, putting a great deal of pressure on users' device experience. Summary of the Invention

[0003] The present application aims to solve one of the technical problems in the related art at least to a certain extent.

[0004] To this end, one purpose of the present application is to propose a data compression method, which obtains the data to be compressed and the data category of the data to be compressed; determines multiple candidate compression strategies corresponding to the data to be compressed based on the data category; obtains the importance of the data to be compressed, and obtains the device status parameters of the current device; determines the target compression strategy from the candidate compression strategies based on the device status parameters and the importance, and determines the compression level corresponding to the target compression strategy; executes the target compression strategy on the data to be compressed according to the compression level to obtain compressed data.

[0005] The second objective of this application is to provide a data compression device.

[0006] The third objective of this application is to provide an electronic device.

[0007] A fourth object of the present application is to provide a non-transitory computer-readable storage medium.

[0008] A fifth object of this application is to provide a computer program product.

[0009] To achieve the above-mentioned purpose, the first embodiment of the present application proposes a data compression method, which obtains the data to be compressed and the data category of the data to be compressed; determines multiple candidate compression strategies corresponding to the data to be compressed based on the data category; obtains the importance of the data to be compressed, and obtains the device status parameters of the current device; determines the target compression strategy from the candidate compression strategies based on the device status parameters and the importance and determines the compression level corresponding to the target compression strategy; executes the target compression strategy on the data to be compressed according to the compression level to obtain compressed data.

[0010] This application can dynamically determine the target compression strategy based on the data type, data importance and device status, and has high flexibility and adaptability. It not only improves the efficiency of data storage and processing, but also ensures a good balance between data quality and storage space, and adapts to the modern and changing device environment and data needs.

[0011] According to one embodiment of the present application, a target compression strategy is determined from candidate compression strategies based on device status parameters and importance, and a compression level corresponding to the target compression strategy is determined, including: determining the target compression strategy from candidate compression strategies based on the importance of the data to be compressed; determining a status score of the current device based on the device status parameters, and determining the compression level corresponding to the target compression strategy based on the status score; wherein the device status parameters include at least one status parameter of the real-time remaining storage space, real-time load status and real-time operation mode of the current device.

[0012] According to one embodiment of the present application, the status score of the current device is determined based on the device status parameters, including: for any status parameter, obtaining a reference score mapping table corresponding to the status parameter; querying the reference score mapping table based on the actual value corresponding to the status parameter to obtain the reference score corresponding to the status parameter; obtaining the preset weight corresponding to each status parameter; and calculating based on the reference score and the preset weight to obtain the status score of the current device.

[0013] According to one embodiment of the present application, a target compression strategy is determined from candidate compression strategies based on the importance of the data to be compressed, including: determining alternative compression strategies from candidate compression strategies based on the importance of the data to be compressed; obtaining the priority corresponding to each alternative compression strategy; and determining the target compression strategy from the alternative compression strategies based on the priority.

[0014] According to one embodiment of the present application, a target compression strategy is executed on the data to be compressed according to the compression level to obtain compressed data, including: obtaining the data amount of the data to be compressed; in response to the data amount being greater than a preset threshold, sequentially dividing the data to be compressed into multiple data blocks to be compressed; sequentially executing the target compression strategy on the data blocks to be compressed according to the compression level to obtain compressed data blocks corresponding to each data block to be compressed; and composing compressed data corresponding to the data to be compressed based on the compressed data blocks.

[0015] According to one embodiment of the present application, the data compression method also includes: obtaining first index information of the data to be compressed; obtaining second index information of the compressed data corresponding to the data to be compressed; obtaining third index information corresponding to each compressed data block corresponding to the compressed data; and establishing an index table based on the first index information, the second index information and the third index information.

[0016] According to one embodiment of the present application, the data compression method also includes: storing the compressed data in a target storage location; in response to monitoring a user's decompression operation on the compressed data, querying an index table to obtain third index information corresponding to each compressed data block corresponding to the compressed data; reading the compressed data blocks block by block from the target storage location into a cache based on the third index information; obtaining a decompression strategy corresponding to the compressed data; executing the decompression strategy on the compressed data blocks block by block in the order in which the compressed data blocks are stored in the cache to obtain decompressed data blocks after decompression, and merging the decompressed data blocks to obtain decompressed data corresponding to the compressed data.

[0017] To achieve the above-mentioned purpose, the second aspect embodiment of the present application proposes a data compression device, including: a first acquisition module, used to obtain the data to be compressed, and obtain the data category of the data to be compressed; a first determination module, used to determine multiple candidate compression strategies corresponding to the data to be compressed based on the data category; a second acquisition module, used to obtain the importance of the data to be compressed, and obtain the device status parameters of the current device; a second determination module, used to determine the target compression strategy from the candidate compression strategies based on the device status parameters and the importance, and determine the compression level corresponding to the target compression strategy; a compression module, used to execute the target compression strategy on the data to be compressed according to the compression level to obtain compressed data.

[0018] According to one embodiment of the present application, the second determination module is further used to: determine a target compression strategy from candidate compression strategies based on the importance of the data to be compressed; determine a status score of the current device based on the device status parameters, and determine a compression level corresponding to the target compression strategy based on the status score; wherein the device status parameters include at least one status parameter of the real-time remaining storage space, real-time load status and real-time operation mode of the current device.

[0019] According to one embodiment of the present application, the second determination module is also used to: obtain a reference score mapping table corresponding to any state parameter; query the reference score mapping table based on the actual value corresponding to the state parameter to obtain the reference score corresponding to the state parameter; obtain the preset weight corresponding to each state parameter; and calculate based on the reference score and the preset weight to obtain the state score of the current device.

[0020] According to one embodiment of the present application, the second determination module is further used to: determine an alternative compression strategy from the candidate compression strategies based on the importance of the data to be compressed; obtain the priority corresponding to each alternative compression strategy; and determine the target compression strategy from the alternative compression strategies based on the priority.

[0021] According to one embodiment of the present application, the compression module is further used to: obtain the data amount of the data to be compressed; in response to the data amount being greater than a preset threshold, divide the data to be compressed into multiple data blocks to be compressed in sequence; execute the target compression strategy on the data blocks to be compressed according to the compression level in turn to obtain a compressed data block corresponding to each data block to be compressed; and compose the compressed data corresponding to the data to be compressed based on the compressed data blocks.

[0022] According to one embodiment of the present application, the data compression device also includes an index establishment module, which is used to: obtain first index information of the data to be compressed; obtain second index information of the compressed data corresponding to the data to be compressed; obtain third index information corresponding to each compressed data block corresponding to the compressed data; and establish an index table based on the first index information, the second index information and the third index information.

[0023] According to one embodiment of the present application, the data compression device further includes a storage module for storing the compressed data in a target storage location.

[0024] According to one embodiment of the present application, the data compression device also includes a decompression module, which is used to: in response to monitoring the user's decompression operation on the compressed data, query the index table to obtain third index information corresponding to each compressed data block corresponding to the compressed data; read the compressed data blocks block by block from the target storage location into the cache based on the third index information; obtain the decompression strategy corresponding to the compressed data; execute the decompression strategy on the compressed data blocks block by block in the order in which the compressed data blocks are stored in the cache to obtain decompressed data blocks after decompression, and obtain decompressed data corresponding to the compressed data based on the merging of the decompressed data blocks.

[0025] To achieve the above-mentioned purpose, the third aspect embodiment of the present application proposes an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to implement the data compression method as described in the first aspect embodiment of the present application.

[0026] To achieve the above-mentioned purpose, the fourth aspect embodiment of the present application proposes a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to implement the data compression method as described in the first aspect embodiment of the present application.

[0027] To achieve the above-mentioned purpose, the fifth embodiment of the present application proposes a computer program product, including a computer program, which, when executed by a processor, implements the data compression method as described in the first embodiment of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which:

[0029] Figure 1 It is a schematic diagram of an exemplary implementation of a data compression method shown in an embodiment of the present application.

[0030] Figure 2 It is a schematic diagram of an exemplary implementation of a data compression method shown in an embodiment of the present application.

[0031] Figure 3 It is a schematic diagram of an exemplary implementation of a data compression method shown in an embodiment of the present application.

[0032] Figure 4 This is an exemplary schematic diagram of a data compression device shown in one embodiment of the present application.

[0033] Figure 5 This is a schematic diagram of an electronic device shown in one embodiment of the present application. DETAILED DESCRIPTION

[0034] The following describes in detail embodiments of the present application, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present application, and should not be construed as limiting the present application.

[0035] Figure 1 is a schematic diagram of an exemplary embodiment of a data compression method shown in this application, such as Figure 1 As shown, the data compression method includes the following steps:

[0036] S101: Obtain data to be compressed, and obtain a data category of the data to be compressed.

[0037] In this application, the data category of the data to be compressed may be a video category, a document category, an image category, or the like.

[0038] In some embodiments, considering that each file type contains a unique identifier in its file header, file header analysis can be used to determine the data type of the data to be compressed. For example, image files in the JPEG (Joint Photographic Experts Group) format typically use FFD8 as the file header; video files (such as MP4 format) typically contain the ftyp identifier in their file header; and document files (such as PDF files) typically begin with the %PDF identifier.

[0039] In some embodiments, the data category of the data to be compressed can be determined by identifying the file extension. For example, a file extension of ".jpg" indicates that the data to be compressed is a picture; a file extension of ".txt" indicates that the data to be compressed is a document.

[0040] In some embodiments, the data type of the data to be compressed can be determined by MIME (Multipurpose Internet Mail Extensions) type identification. For example, a MIME type of "image / jpeg" indicates that the data to be compressed is an image; a MIME type of "application / pdf" indicates that the data to be compressed is a document.

[0041] In some embodiments, the data category of the data to be compressed may be determined by analyzing the characteristics of the data to be compressed, for example, by determining the category of the data to be compressed based on the characteristics of the data (such as byte distribution or character encoding).

[0042] S102: Determine multiple candidate compression strategies corresponding to the data to be compressed based on the data category.

[0043] In this application, each data category can be pre-set with multiple compression strategies. For example, the document category can be pre-set with the LZ77 compression algorithm and the Deflate compression algorithm.

[0044] In this application, each data category can be set with its corresponding lossy compression strategy and lossless compression strategy.

[0045] There may be one or more lossy compression strategies corresponding to each data category.

[0046] There may be one or more lossless compression strategies corresponding to each data category.

[0047] After the data category of the data to be compressed is determined, a compression strategy corresponding to the data category is determined as a candidate compression strategy corresponding to the data to be compressed.

[0048] S103: Obtain the importance of the data to be compressed, and obtain the device status parameters of the current device.

[0049] The importance of the data to be compressed indicates the importance of the data to be compressed. For example, if the data to be compressed is an important paper of the user, its importance is relatively high; if the data to be compressed is temporary cache data when browsing certain websites, its importance is relatively low.

[0050] A deep learning-based model (such as a convolutional neural network or a long short-term memory network) can be used to extract features from the data and assess its "information density" to determine the importance of the data to be compressed. For example, for image data, an image classification network might be used to identify the image's content and determine whether it contains important information.

[0051] Among them, the device status parameters of the current device are used to represent the device status of the current device. For example, the device status parameters may include the device's current memory usage, central processing unit (CPU) usage, network bandwidth, hard disk space, temperature, power consumption and other parameters.

[0052] S104: Determine a target compression strategy from candidate compression strategies based on the device state parameters and the importance, and determine a compression level corresponding to the target compression strategy.

[0053] In some implementations, if it is determined based on device status parameters that current device resources are limited (e.g., insufficient remaining storage space), a candidate compression strategy with the lowest compression ratio from the candidate compression strategies identified above may be determined as a target compression strategy to further conserve device resources. At the same time, the compression level corresponding to the target compression strategy may be ultimately determined based on the importance of the data to be compressed. For example, if the importance of the data to be compressed is relatively high, the compression level corresponding to the target compression strategy may be determined to be a low compression level to ensure data integrity as much as possible under conditions of limited device resources. If the importance of the data to be compressed is relatively low, the compression level corresponding to the target compression strategy may be determined to be a high compression level to maximize device resource conservation.

[0054] Among them, determining the compression level corresponding to the target compression strategy can also be understood as determining the compression adjustment factor corresponding to the target compression strategy. For example, when compressing video data, the corresponding compression adjustment factor can be the compression bit rate. Different compression bit rates can be regarded as corresponding to different compression levels.

[0055] In other implementations, a reinforcement learning decision model based on device state parameters and data importance is established. These two components together constitute the state space of the current system, and the combination of compression strategies and their compression levels serves as the action space. The reward function is defined based on the target compression strategy's selection efficiency, data transmission time, and computational resource consumption. For example, when a device is in a "good" state, a high compression ratio may be advantageous; whereas, when the device is in a poor state, a low compression ratio (for a lighter computational load) may be more appropriate. The reinforcement learning decision model determines the target compression strategy and the corresponding compression level from candidate compression strategies through continuous trial and error, updating, and optimization.

[0056] S105 , executing a target compression strategy on the data to be compressed according to the compression level to obtain compressed data.

[0057] After determining the target compression strategy and the compression level corresponding to the target compression strategy, the Application Programming Interface (API) corresponding to the target compression strategy can be directly called to execute the target compression strategy on the compressed data according to the compression level to obtain compressed data.

[0058] Optionally, when executing a target compression strategy on the data to be compressed according to the compression level, a batch processing compression method may be selected.

[0059] The embodiment of the present application proposes a data compression method, including: obtaining data to be compressed, and obtaining the data category of the data to be compressed; determining multiple candidate compression strategies corresponding to the data to be compressed based on the data category; obtaining the importance of the data to be compressed, and obtaining the device status parameters of the current device; determining a target compression strategy from the candidate compression strategies based on the device status parameters and the importance, and determining the compression level corresponding to the target compression strategy; executing the target compression strategy according to the compression level on the data to be compressed to obtain compressed data. The present application dynamically determines the target compression strategy based on the data type, data importance, and device status, and has high flexibility and adaptability. It not only improves the efficiency of data storage and processing, but also ensures a good balance between data quality and storage space, and adapts to the modern and changing device environment and data requirements.

[0060] Furthermore, the device status parameters of the current device introduced above may include at least one status parameter of the current device's real-time remaining storage space, real-time load status (such as CPU and memory usage, which can be used to determine whether the current device is in a high-load or idle state) and real-time operating mode (such as charging mode, flight mode, etc.).

[0061] Furthermore, the specific steps of determining the target compression strategy from the candidate compression strategies based on the device status parameters and importance, and determining the compression level corresponding to the target compression strategy, may include: determining the target compression strategy from the candidate compression strategies based on the importance of the data to be compressed, for example, a lossless compression strategy may be used for data with higher importance to ensure data integrity, while a lossy compression strategy may be used for data with lower importance to save more device space; then, determining the status score of the current device based on the device status parameters, and determining the compression level corresponding to the target compression strategy based on the status score. For example, if the status score indicates that the current device load is high and the status is poor, a high compression level is selected to quickly complete the compression, reduce real-time resource consumption, and improve compression efficiency; if the status score indicates that the current device load is low and the status is good, a low compression level is selected to ensure data integrity as much as possible.

[0062] Among them, the specific steps of determining the status score of the current device based on the device status parameters include: for any status parameter, obtaining the reference score mapping table corresponding to the status parameter; querying the reference score mapping table based on the actual value corresponding to the status parameter to obtain the reference score corresponding to the status parameter; obtaining the preset weight corresponding to each status parameter; and calculating based on the reference score and the preset weight to obtain the status score of the current device.

[0063] For example, assuming that the device status parameters include three status parameters: real-time remaining storage space, real-time load status, and real-time operation mode, then the reference score mapping tables corresponding to the three status parameters are obtained. For example, the reference score mapping table corresponding to the real-time remaining storage space is used to represent the mapping relationship between the remaining storage space and the reference score (for example, the mapping relationship can be set based on the idea that the smaller the remaining space, the smaller the reference score). The mapping table can be queried based on the real-time remaining storage space of the current device to obtain the reference score corresponding to the real-time remaining storage space status parameter; the reference score mapping table corresponding to the real-time load status is used to represent the mapping relationship between the load status and the reference score (for example, the mapping relationship can be set based on the idea that the higher the load, the smaller the reference score). The mapping table can be queried based on the real-time load status of the current device to obtain the reference score corresponding to the real-time load status status parameter; the reference score mapping table corresponding to the real-time operation mode is used to represent the mapping relationship between the operation mode and the reference score (for example, the night mode can be set to a higher score and the working mode to a lower score). The mapping table can be queried based on the real-time operation mode of the current device to obtain the reference score corresponding to the real-time operation mode status parameter. After obtaining the three reference scores above, a weighted sum is taken to determine the current device status score. A lower score indicates a worse device status (the device is approaching a performance bottleneck or experiencing significant pressure); a higher score indicates sufficient device resources and a better device status.

[0064] Figure 2 is a schematic diagram of an exemplary embodiment of a data compression method shown in this application, such as Figure 2 As shown, the data compression method includes the following steps:

[0065] S201: Acquire data to be compressed, and acquire a data category of the data to be compressed.

[0066] S202: Determine multiple candidate compression strategies corresponding to the data to be compressed based on the data category.

[0067] S203: Obtain the importance of the data to be compressed, and obtain the device status parameters of the current device.

[0068] Regarding the specific implementation of steps S201 to S203, reference may be made to the detailed introduction of the relevant parts in the above embodiment, which will not be elaborated here.

[0069] S204: Determine an alternative compression strategy from the candidate compression strategies based on the importance of the data to be compressed.

[0070] Exemplarily, if the importance of the data to be compressed is high, multiple lossless compression strategies are determined from the candidate compression strategies as alternative compression strategies.

[0071] Exemplarily, if the importance of the data to be compressed is low, multiple lossy compression strategies are determined from the candidate compression strategies as alternative compression strategies.

[0072] S205: Obtain the priority corresponding to each candidate compression strategy.

[0073] Considering that there are often multiple lossy compression strategies or lossless compression strategies corresponding to the same data category, the concept of strategy priority is introduced in this embodiment.

[0074] If there are multiple alternative compression strategies determined above, in this application, after determining the alternative compression strategies, the priority corresponding to each alternative compression strategy is obtained. The strategy priority can be manually set by the user, pre-set at the factory, or dynamically adjusted by the device based on the user's historical preferences.

[0075] S206: Determine a target compression strategy from the candidate compression strategies based on the priority.

[0076] In this application, the candidate compression strategy with the highest priority is used as the target compression strategy.

[0077] S207: Determine a status score of the current device based on the device status parameter, and determine a compression level corresponding to the target compression strategy based on the status score.

[0078] The specific steps of determining the status score of the current device based on the device status parameters have been specifically introduced above and will not be repeated here.

[0079] After determining the status score of the current device, the status score is compared with a preset score range to obtain the target score range in which the status score is located, and the compression level corresponding to the target score range is obtained as the compression level corresponding to the target compression strategy.

[0080] S208: Execute the target compression strategy on the data to be compressed according to the compression level to obtain compressed data.

[0081] After determining the target compression strategy and the compression level corresponding to the target compression strategy, the API interface corresponding to the target compression strategy can be directly called to execute the target compression strategy on the data to be compressed according to the compression level to obtain compressed data.

[0082] The embodiment of the present application dynamically determines the target compression strategy based on the data type, data importance, device status, and policy priority, and has high flexibility and adaptability. It not only improves the efficiency of data storage and processing, but also ensures a good balance between data quality and storage space, and adapts to the modern and changing device environment and data requirements.

[0083] Figure 3 is a schematic diagram of an exemplary embodiment of a data compression method shown in this application, such as Figure 3 As shown, the data compression method includes the following steps:

[0084] S301: Obtain data to be compressed, and obtain the data category of the data to be compressed.

[0085] S302: Determine multiple candidate compression strategies corresponding to the data to be compressed based on the data category.

[0086] S303: Obtain the importance of the data to be compressed, and obtain the device status parameters of the current device.

[0087] S304: Determine a target compression strategy from candidate compression strategies based on the device state parameter and the importance, and determine a compression level corresponding to the target compression strategy.

[0088] Regarding the specific implementation of steps S301 to S304, please refer to the detailed introduction of the relevant parts in the above embodiment, which will not be repeated here.

[0089] S305: Obtain the data volume of the data to be compressed.

[0090] For example, suppose the data to be compressed is a video file with a size of 3G.

[0091] S306 : In response to the data amount being greater than a preset threshold, the data to be compressed is divided into a plurality of data blocks to be compressed in sequence.

[0092] A data volume threshold is preset. If the volume of the data to be compressed is greater than the preset threshold, the data to be compressed is considered to be compressed block by block. That is, the data to be compressed is first divided into multiple data blocks to be compressed in sequence. For example, the data to be compressed can be divided into 10 data blocks to be compressed in sequence.

[0093] S307 , executing the target compression strategy on the data blocks to be compressed according to the compression levels in turn, and obtaining a compressed data block corresponding to each data block to be compressed.

[0094] In this application, the target compression strategy is applied to the data blocks to be compressed according to the compression level in the order of the data blocks to be compressed, thereby obtaining a compressed data block corresponding to each data block to be compressed. For example, if the data to be compressed is sequentially divided into 10 data blocks to be compressed, then 10 compressed data blocks can be obtained.

[0095] S308 , composing compressed data corresponding to the data to be compressed based on the compressed data blocks.

[0096] The compressed data blocks are merged in the order of the data blocks to be compressed to obtain the complete compressed data corresponding to the original data to be compressed.

[0097] The embodiment of the present application divides the data to be compressed into multiple data blocks and compresses them block by block, which can make the compression process more efficient, better utilize computing resources and parallelize processing, thereby improving the compression speed; by dynamically selecting an appropriate compression strategy based on the data type, device status parameters and data importance, it is ensured that the execution of the compression task will not place an excessive burden on the device performance.

[0098] Furthermore, after the compressed data is obtained, the compressed data is stored in a target storage location, such as an SD card. If the data to be compressed is compressed block by block, the compressed data can also be stored in blocks to reduce the single write burden on the file system.

[0099] Furthermore, after the compressed data is stored in the target storage location, the original data to be compressed may be deleted.

[0100] Furthermore, the compressed data can retain the same path and file name as the original data to be compressed, so that users will not feel the change of storage structure when accessing the file.

[0101] In some implementations, the compressed data can be managed using standard identifiers of the file system (such as file pointers, index nodes, etc.), which ensures that the file system can still recognize and process the files even if the data is compressed.

[0102] In some implementations, the compressed data is written using standard APIs provided by the file system to ensure compatibility with the file system, for example, using standard functions such as fopen, fwrite, and fread for file operations.

[0103] In some implementations, compressed data is read and written through the original file system interface without making underlying modifications to the file system to avoid affecting device compatibility.

[0104] In some implementations, when compressing data, the file header and metadata (such as file type, creation time, etc.) are preserved and processed correctly. This allows the system to correctly identify the basic information of the file even if the file is compressed.

[0105] In some implementations, properties such as permissions and timestamps of the data to be compressed are preserved to avoid interference with the file system.

[0106] In some implementations, the present application considers creating an index table to store index information of related data, such as the original position before compression, the position after compression, the compression status, and other information. Specifically, if the data to be compressed is compressed block by block, first index information of the data to be compressed is obtained; second index information of the compressed data corresponding to the data to be compressed is obtained; third index information corresponding to each compressed data block corresponding to the compressed data is obtained; and an index table is established based on the first index information, the second index information, and the third index information.

[0107] In some implementations, if the size of a particular piece of data to be compressed is less than or equal to a preset threshold, the data to be compressed need not be compressed in blocks according to the above steps. Instead, the target compression strategy can be directly applied to the data to be compressed according to the compression level to obtain compressed data. This also means that no blocks of data to be compressed or compressed data are generated during the compression process. This also means that, in the index table, only the first index information for the data to be compressed and the second index information for the compressed data corresponding to the data to be compressed need to be stored.

[0108] In some implementations, if a user's decompression operation on a certain compressed data is monitored, an index table is queried. If third index information corresponding to each compressed data block corresponding to the compressed data is found in the index table (that is, it indicates that block compression was performed when the compressed data was obtained), the third index information corresponding to each compressed data block corresponding to the compressed data in the index table is obtained; based on the third index information, the compressed data blocks are read block by block from the target storage location into the cache; a decompression strategy corresponding to the compressed data is obtained; the decompression strategy is executed on the compressed data blocks block by block in the order in which the compressed data blocks are stored in the cache to obtain decompressed data blocks, and decompressed data corresponding to the compressed data is obtained based on the merging of the decompressed data blocks. This block-by-block decompression method can increase the decompression speed and reduce memory usage.

[0109] In some implementations, if a user's decompression operation on compressed data is monitored, the index table is queried. If only the second index information corresponding to the compressed data is found in the index table, and the third index information corresponding to each compressed data block of the compressed data is not found (that is, it means that block compression was not performed when the compressed data was obtained), the second index information corresponding to the compressed data in the index table is obtained, and the compressed data block is read from the target storage location into the cache based on the second index information, and the decompression strategy corresponding to the compressed data is obtained, and the decompression strategy is executed on the compressed data to obtain the decompressed data corresponding to the compressed data.

[0110] In some implementations, after the decompressed data is obtained, the decompressed data may be stored in the original file location corresponding to the compressed data.

[0111] In some implementations, a cache mechanism may be used when compressing the data to be compressed. That is, the data to be compressed is placed in a cache, and after compression is complete, the compressed data is stored in a target storage location. This cache mechanism can reduce the number of reads and writes to the SD card and improve overall performance.

[0112] In some implementations, during the data writing process, the system performs a data integrity check to ensure that the compressed data can be correctly decompressed and restored. This can be done using a checksum or hash algorithm to ensure that the data is not corrupted.

[0113] To optimize performance, you can decompress files on demand, only decompressing them when they are actually accessed. This reduces storage space usage and improves system responsiveness.

[0114] In some implementations, in some cases, memory-mapped file techniques (such as mmap) are used to map the compressed data into memory, thereby loading blocks of data on demand when needed without having to read the entire file into a memory buffer.

[0115] In some implementations, during the decompression process, the next compressed data block can be read asynchronously while the current block is still being decompressed. This can reduce the delay between reading and decompression and improve overall processing speed.

[0116] In some implementations, when decompressing a data block, the data block that will be decompressed may be pre-read and loaded into a memory buffer in advance to reduce delays caused by block switching.

[0117] In some implementations, streaming decompression is used, which processes only the data in the current block during decompression, rather than decompressing the entire file at once. This can reduce I / O operations and memory usage while maintaining a high reading speed.

[0118] In some implementations, once a data block is decompressed and processed, the associated memory resources are released to ensure that memory usage is kept to a minimum.

[0119] In some implementations, the decompressed data blocks may be delayed in being written to the final file, thereby reducing frequent operations on the storage medium and improving writing efficiency.

[0120] In some implementations, batch operations can be performed on the decompression results of multiple data blocks, for example, they can be written to the target location at one time after decompression is completed, thereby reducing the number of writes to the disk.

[0121] In some implementations, whenever a file is compressed or decompressed, the system updates the index table to reflect the latest file status. In this way, when accessing files, the system can quickly find and locate the compressed data position of the file.

[0122] Figure 4 This is an exemplary schematic diagram of a data compression device shown in this application. Figure 4 As shown, the data compression device 400 includes a first acquisition module 401, a first determination module 402, a second acquisition module 403, a second determination module 404 and a compression module 405, wherein:

[0123] The first acquisition module 401 is configured to acquire the data to be compressed and the data category of the data to be compressed.

[0124] The first determination module 402 is configured to determine a plurality of candidate compression strategies corresponding to the data to be compressed based on the data category.

[0125] The second acquisition module 403 is used to acquire the importance of the data to be compressed and to acquire the device status parameters of the current device.

[0126] The second determining module 404 is configured to determine a target compression strategy from candidate compression strategies based on the device state parameters and the importance, and to determine a compression level corresponding to the target compression strategy.

[0127] The compression module 405 is configured to execute a target compression strategy on the data to be compressed according to the compression level to obtain compressed data.

[0128] This device can dynamically determine the target compression strategy based on the data type, data importance and device status. It has high flexibility and adaptability, which not only improves the efficiency of data storage and processing, but also ensures a good balance between data quality and storage space, and adapts to the modern and changing device environment and data requirements.

[0129] Furthermore, the second determination module 404 is also used to: determine a target compression strategy from candidate compression strategies based on the importance of the data to be compressed; determine a status score of the current device based on the device status parameters, and determine a compression level corresponding to the target compression strategy based on the status score; wherein the device status parameters include at least one status parameter of the real-time remaining storage space, real-time load status and real-time operation mode of the current device.

[0130] Furthermore, the second determination module 404 is also used to: obtain a reference score mapping table corresponding to any state parameter; query the reference score mapping table based on the actual value corresponding to the state parameter to obtain the reference score corresponding to the state parameter; obtain the preset weight corresponding to each state parameter; and calculate based on the reference score and the preset weight to obtain the state score of the current device.

[0131] Furthermore, the second determination module 404 is further configured to: determine an alternative compression strategy from the candidate compression strategies based on the importance of the data to be compressed; obtain a priority corresponding to each alternative compression strategy; and determine a target compression strategy from the alternative compression strategies based on the priority.

[0132] Furthermore, the compression module 405 is also used to: obtain the data amount of the data to be compressed; in response to the data amount being greater than a preset threshold, divide the data to be compressed into multiple data blocks to be compressed in sequence; execute the target compression strategy on the data blocks to be compressed according to the compression level in turn to obtain the compressed data block corresponding to each data block to be compressed; and compose the compressed data corresponding to the data to be compressed based on the compressed data blocks.

[0133] Furthermore, the data compression device 400 also includes an index establishment module, which is used to: obtain first index information of the data to be compressed; obtain second index information of the compressed data corresponding to the data to be compressed; obtain third index information corresponding to each compressed data block corresponding to the compressed data; and establish an index table based on the first index information, the second index information and the third index information.

[0134] Furthermore, the data compression device 400 further includes a storage module for storing the compressed data in a target storage location.

[0135] Furthermore, the data compression device 400 also includes a decompression module, which is used to: in response to monitoring the user's decompression operation on the compressed data, query the index table to obtain third index information corresponding to each compressed data block corresponding to the compressed data; read the compressed data blocks block by block from the target storage location into the cache based on the third index information; obtain the decompression strategy corresponding to the compressed data; execute the decompression strategy on the compressed data blocks block by block in the order in which the compressed data blocks are stored in the cache to obtain decompressed data blocks after decompression, and obtain decompressed data corresponding to the compressed data based on the merging of the decompressed data blocks.

[0136] In order to implement the above embodiment, the present application also provides an electronic device 500, such as Figure 5As shown, the electronic device 500 includes: a processor 501 and a memory 502 communicatively connected to the processor, the memory 502 stores instructions that can be executed by at least one processor, and the instructions are executed by at least one processor 501 to implement the data compression method shown in the above embodiment.

[0137] In order to implement the above embodiment, the embodiment of the present application further proposes a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable a computer to implement the data compression method shown in the above embodiment.

[0138] In order to implement the above embodiments, the embodiments of the present application further provide a computer program product, including a computer program, which implements the data compression method shown in the above embodiments when executed by a processor.

[0139] In the description of the present application, it should be understood that the terms "center", "longitudinal", "lateral", "length", "width", "thickness", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside", "clockwise", "counterclockwise", "axial", "radial", "circumferential" and the like indicate orientations or positional relationships based on the orientations or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be understood as a limitation on the present application.

[0140] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of the technical features being referred to. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features. Throughout the description of this application, "plurality" means two or more, unless otherwise specifically defined.

[0141] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art can combine and combine different embodiments or examples described in this specification and features of different embodiments or examples without contradiction.

[0142] Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limitations on the present application. Ordinary technicians in this field can change, modify, replace and modify the above embodiments within the scope of the present application.

Claims

1. A data compression method, characterized in that: include: Obtaining data to be compressed, and obtaining a data category of the data to be compressed; determining a plurality of candidate compression strategies corresponding to the data to be compressed based on the data category; Obtaining the importance of the data to be compressed, and obtaining device status parameters of the current device; Determining a target compression strategy from the candidate compression strategies based on the device state parameter and the importance, and determining a compression level corresponding to the target compression strategy; The target compression strategy is executed on the data to be compressed according to the compression level to obtain compressed data.

2. The method according to claim 1, characterized in that The determining of a target compression strategy from the candidate compression strategies based on the device state parameter and the importance and determining a compression level corresponding to the target compression strategy includes: determining a target compression strategy from the candidate compression strategies based on the importance of the data to be compressed; Determining a status score of the current device based on the device status parameter, and determining a compression level corresponding to the target compression strategy based on the status score; The device status parameter includes at least one of the following status parameters: real-time remaining storage space, real-time load status, and real-time operation mode of the current device.

3. The method according to claim 2, characterized in that Determining the status score of the current device based on the device status parameter includes: For any of the state parameters, obtaining a reference score mapping table corresponding to the state parameter; Querying the reference score mapping table based on the actual value corresponding to the state parameter to obtain the reference score corresponding to the state parameter; Obtaining a preset weight corresponding to each of the state parameters; A calculation is performed based on the reference score and the preset weight to obtain a status score of the current device.

4. The method according to claim 3, characterized in that The determining of a target compression strategy from the candidate compression strategies based on the importance of the data to be compressed includes: determining an alternative compression strategy from the candidate compression strategies based on the importance of the data to be compressed; Obtaining the priority corresponding to each of the alternative compression strategies; A target compression strategy is determined from the candidate compression strategies based on the priority.

5. The method according to any one of claims 1 to 4, characterized in that The step of executing the target compression strategy on the data to be compressed according to the compression level to obtain compressed data includes: Obtaining the amount of the data to be compressed; In response to the data amount being greater than a preset threshold, dividing the data to be compressed into a plurality of data blocks to be compressed in sequence; executing the target compression strategy on the data blocks to be compressed in sequence according to the compression level to obtain a compressed data block corresponding to each of the data blocks to be compressed; Compressed data corresponding to the data to be compressed is composed based on the compressed data blocks.

6. The method according to claim 5, characterized in that The method further comprises: Obtaining first index information of the data to be compressed; Obtaining second index information of compressed data corresponding to the data to be compressed; Obtaining third index information corresponding to each compressed data block corresponding to the compressed data; An index table is created based on the first index information, the second index information, and the third index information.

7. The method according to claim 6, characterized in that The method further comprises: storing the compressed data in a target storage location; In response to detecting a user's decompression operation on the compressed data, querying the index table to obtain third index information corresponding to each compressed data block corresponding to the compressed data; reading the compressed data blocks from the target storage location into a cache block by block based on the third index information; Obtaining a decompression strategy corresponding to the compressed data; The decompression strategy is executed on each compressed data block in the order in which the compressed data blocks are stored in the cache to obtain decompressed data blocks, and decompressed data corresponding to the compressed data is obtained by merging the decompressed data blocks.

8. A data compression device, characterized in that: include: A first acquisition module is used to acquire data to be compressed and acquire a data category of the data to be compressed; A first determining module, configured to determine a plurality of candidate compression strategies corresponding to the data to be compressed based on the data category; A second acquisition module is used to obtain the importance of the data to be compressed and to obtain the device status parameters of the current device; a second determining module, configured to determine a target compression strategy from the candidate compression strategies based on the device state parameter and the importance, and to determine a compression level corresponding to the target compression strategy; The compression module is used to execute the target compression strategy on the data to be compressed according to the compression level to obtain compressed data.

9. An electronic device comprising: at least one processor; as well as, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 7.

10. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1 to 7.

Citation Information

Cited By

  • Data processing method, system and device

    CN121280144A

  • Data processing method, system and apparatus

    CN121280144B

  • Method for automatically optimizing cue words of AI large model in big data scene

    CN121350060A

  • Time window-based time sequence data compression hierarchical storage method and system

    CN121367499A