Data compression method and electronic equipment
By compressing files with empty files, the problem of storage resource occupation in data backup and recovery is solved, and more efficient storage resource utilization and data backup and recovery efficiency are achieved.
Patent Information
- Application Number
- CN202311050341.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-18
- Publication Date
- 2025-02-21
AI Technical Summary
In data backup and recovery scenarios, how to reduce the resource utilization of backup data on storage devices and improve the efficiency of storage resources.
By compressing files with file voids, the compression of the hollow part is achieved using specific data compression methods and formats, including storing instructions of the compression algorithm in the file block header.
The compressed files occupy a small storage space and high efficiency in utilizing storage resources, which improves the efficiency of data backup and recovery.
Smart Images

Figure CN119493689A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of terminal device software, and in particular, to a data compression method and electronic device. Background Art
[0002] Data backup and recovery is an effective measure to protect personal data on electronic devices used by users, prevent virus intrusion, accidental deletion and data corruption, etc. With the hardware iteration of electronic devices, the number of applications that can run on electronic devices is increasing, and the amount of personal data of users stored on electronic devices is also increasing.
[0003] In data backup and / or recovery scenarios, how to reduce the resource occupation of the backup data on the storage device and improve the utilization efficiency of the storage resources is an issue worth considering. Summary of the invention
[0004] The present application provides a data compression method, and an electronic device can compress files with file holes. The compressed files occupy a small storage space and have high utilization efficiency of storage resources.
[0005] In a first aspect, a method for data compression is provided, which is applied to an electronic device, and the method comprises: receiving a first input; in response to the first input, saving the first file as a second file when the first file includes a hole portion; wherein the first input is used to indicate performing data backup on the first file, the first file includes a hole portion and a data portion, the second file includes a target field and a data portion, and the target field is used to indicate a compression algorithm for performing data compression on the hole portion.
[0006] In a possible implementation manner, the electronic device may determine whether the first file includes a hole portion.
[0007] In a possible implementation, the electronic device may determine whether the first file includes a hole portion by searching whether the first file contains continuous zero bits. The electronic device may also determine whether the first file includes a hole portion based on whether the first file is a sparse file.
[0008] In one possible implementation, the first input may be used to instruct to perform a local data backup of the first file, or the first input may also be used to instruct to back up the first file on other storage devices, such as a cloud device or another electronic device relative to the current electronic device.
[0009] The hole portion refers to a portion of the first file that is not filled with actual data but still occupies disk space. Correspondingly, the data portion refers to a portion of the first file that is filled with actual data. In some examples, the hole portion may refer to a portion of the first file that is filled with multiple consecutive zeros.
[0010] The electronic device can compress the hole part in the first file, and save the target field that can indicate the compression algorithm for compressing the hole part in the compressed second file. The content of the second file is substantially consistent with the content of the first file. In other words, the first file can be restored using the second file. The second file occupies less storage resources, and the storage resources of the storage device are more efficiently utilized.
[0011] In combination with the first aspect, in some implementations of the first aspect, the second file includes a file block header and file block data, the file block header includes a target field, and the file block data includes a data portion.
[0012] Using the data storage format of "file block header + file block data" to store the compressed second file, and performing processing operations such as sending, receiving, and verifying the second file according to this format is beneficial to improving the processing efficiency of the compressed file, improving the processing and management efficiency of the electronic device for the compressed data, and improving the stability and security of the compressed data.
[0013] In combination with the first aspect, in some implementations of the first aspect, the file block header further includes a first field and a second field, the first field is used to indicate the number of bytes of the first file, and the second field is used to indicate the number of bytes of the data portion.
[0014] Based on the number of bytes of the first file and the number of bytes of the data portion, the electronic device can perform data verification when performing processing operations such as sending and receiving the compressed file. For example, when decompressing the second file, the electronic device can determine whether the number of bytes of the decompressed file is equal to the number of bytes of the first file to determine whether the first file is complete. Similarly, when sending the second file, the device receiving the second file can determine whether the received second file is complete based on whether the number of bytes of the received file block data is equal to the number of bytes of the data portion. Including the first field and the second field in the file block header is conducive to reducing the probability that the compressed file cannot be restored to the pre-compression file, thereby improving the reliability of the data compression method provided by the present application.
[0015] In combination with the first aspect, in some implementations of the first aspect, the file block header further includes a third field and / or a fourth field, the third field is used to identify the file block header, and the fourth field is used to indicate a file format version number of the second file.
[0016] The third field and the fourth field can both be used to identify whether the current file is a file compressed from the hole portion. Using the third field and / or the fourth field is conducive to realizing rapid identification of the file type by the electronic device, thereby also being conducive to improving the processing efficiency of the electronic device for the compressed file.
[0017] In combination with the first aspect, in some implementations of the first aspect, the file block header further includes a fifth field, and the fifth field is used to indicate an extended function supported by the second file.
[0018] A fifth field is set in the file block header of the compressed second file, and the fifth field is similar to a reserved field. The setting of the fifth field can improve the scalability of the data compression method provided by the present application. In some examples, the identification of the subdivision type of the compression method for the hollow part can be stored in the fifth field.
[0019] In combination with the first aspect, in certain implementations of the first aspect, in response to a first input, when the first file includes a hole portion, saving the first file as a second file includes: determining whether the file system of the electronic device supports a sparse file feature and whether the first file is a sparse file; and when the file system of the electronic device supports the sparse file feature and the first file is a sparse file, saving the first file as a second file.
[0020] A sparse file can be considered as a file that contains holes.
[0021] When the file system of the electronic device supports sparse file characteristics and the first file is a sparse file, the electronic device can perform the data compression method provided by the present application on the sparse file. The data compression method provided by the present application can be applied to some existing files and has good compatibility.
[0022] In combination with the first aspect, in some implementations of the first aspect, the length of the hole portion is greater than or equal to a first threshold.
[0023] In a possible implementation, the hole portion can be regarded as all-zero data of a certain length. Before compressing the first file, it is first necessary to determine whether the first file is a file containing a hole portion. Generally, this can be determined by searching whether there is a part filled with zeros in the file.
[0024] In order to improve the efficiency of detecting the hole part, the length of the hole part can be set to be greater than or equal to the first threshold, which is equivalent to not compressing the hole part for files whose length of the hole part is less than the first threshold. This is also helpful to improve the processing efficiency of multiple files by the electronic device to a certain extent.
[0025] In combination with the first aspect, in certain implementations of the first aspect, the second file includes a file block header and file block data, the file block header includes a target field, the file block data includes a data portion, the first threshold is the number of bytes of the file block header, and in response to the first input, when the first file includes a hole portion, saving the first file as the second file includes: determining whether the length of the hole portion is greater than or equal to the first threshold; and when the length of the hole portion is greater than or equal to the first threshold, saving the first file as the second file.
[0026] Taking into account that the newly added file block header of the compressed file needs to occupy a certain amount of storage space, in order to increase the probability of saving storage resources by the data compression method provided in this application, data compression is only performed on files whose number of bytes after compression is smaller than the number of bytes of the file before compression.
[0027] In combination with the first aspect, in certain implementations of the first aspect, in response to the first input, when the first file includes a hole portion, saving the first file as a second file includes: determining whether the compression rate of the first file is less than or equal to a second threshold; and when the compression rate of the first file is less than or equal to the second threshold, saving the first file as the second file.
[0028] In some scenarios, the compression rate can also be called the sparseness rate, which refers to the ratio of the space occupied by the actual data in the file to the total space occupied by the file. The smaller the compression rate, the larger the proportion of the empty part in the file. The smaller the space occupied by the compressed file after compressing the empty part in the file.
[0029] Since compressing files requires a certain amount of computing resources, the more files that need to be compressed, the longer the computing resources will be used to compress the files. By compressing files with relatively high compression rates, a relative balance between computing resource consumption and storage resource usage can be achieved to a certain extent.
[0030] In combination with the first aspect, in certain implementations of the first aspect, the first file is a file of the target application, and before saving the first file as the second file in response to the first input, a first database is created, and the first database is used to save data information of the target application, and the data information of the target application includes the second file.
[0031] Processing data using applications as basic units is beneficial to improving the management efficiency of electronic devices for files that need to be backed up or restored.
[0032] In combination with the first aspect, in some implementations of the first aspect, the first database includes first information, and the first information is used to indicate that data compression has been performed on the hole portion in the first file.
[0033] In a possible implementation, if the hole portion in the file has been compressed, the first information may indicate that the hole portion in the file has been compressed. If the hole portion in the file has not been compressed, the first information may indicate that the hole portion in the file has not been compressed.
[0034] It should be noted that the hole part is not compressed, which includes two situations: the file does not contain the hole part and the file contains the hole part but the hole part is not compressed.
[0035] According to the first information in the first database, the electronic device can determine the compression method of the first file, and according to the compression method, the electronic device can determine the decompression method of the file. This technical solution is conducive to improving the efficiency of restoring compressed data to a certain extent.
[0036] In combination with the first aspect, in some implementations of the first aspect, the method further includes: sending the second file to a cloud-side device, and the cloud-side device is used to store the second file.
[0037] The data compression method provided in the present application is suitable for scenarios where data of electronic devices are backed up in the cloud. It can improve the utilization efficiency of storage resources of cloud-side devices to a certain extent, and is conducive to improving the efficiency of data backup and recovery of electronic devices.
[0038] In combination with the first aspect, in some implementations of the first aspect, the number of bytes of the first file is greater than or equal to a third threshold, the first file is composed of multiple third files, and the number of bytes of the third files is less than the third threshold.
[0039] Electronic devices may contain a large number of files that take up relatively small storage space. The process of compressing and uploading each small file individually requires more computing resources. By packaging multiple small files into a large file and compressing the large file before uploading it, it is beneficial to improve the utilization efficiency of the computing resources of the electronic device.
[0040] The beneficial effects and detailed descriptions of the following technical solutions can be referred to the relevant descriptions in the first aspect, and for the sake of brevity, they are not elaborated below.
[0041] In a second aspect, a data compression device is provided, which includes an acquisition module and a processing module, wherein the acquisition module is used to: acquire a first input; the processing module is used to: in response to the first input, save the first file as a second file when the first file includes a hole part; wherein the first input is used to indicate performing data backup on the first file, the first file includes a hole part and a data part, the second file includes a target field and a data part, and the target field is used to indicate a compression algorithm for performing data compression on the hole part.
[0042] In combination with the second aspect, in some implementations of the second aspect, the second file includes a file block header and file block data, the file block header includes a target field, and the file block data includes a data portion.
[0043] In combination with the second aspect, in some implementations of the second aspect, the file block header also includes a first field and a second field, the first field is used to indicate the number of bytes of the first file, and the second field is used to indicate the number of bytes of the data part.
[0044] In combination with the second aspect, in some implementations of the second aspect, the file block header further includes a third field and / or a fourth field, the third field is used to identify the file block header, and the fourth field is used to indicate a file format version number of the second file.
[0045] In combination with the second aspect, in some implementations of the second aspect, the file block header further includes a fifth field, and the fifth field is used to indicate an extended function supported by the second file.
[0046] In combination with the second aspect, in certain implementations of the second aspect, the processing module is specifically used to: determine whether the file system of the electronic device supports the sparse file feature and whether the first file is a sparse file; if the file system of the electronic device supports the sparse file feature and the first file is a sparse file, save the first file as a second file.
[0047] In combination with the second aspect, in some implementations of the second aspect, the length of the hole portion is greater than or equal to a first threshold.
[0048] In combination with the second aspect, in certain implementations of the second aspect, the second file includes a file block header and file block data, the file block header includes a target field, the file block data includes a data part, the first threshold is the number of bytes of the file block header, and the processing module is specifically used to: determine whether the length of the empty part is greater than or equal to the first threshold; if the length of the empty part is greater than or equal to the first threshold, save the first file as the second file.
[0049] In combination with the second aspect, in certain implementations of the second aspect, the processing module is specifically used to: determine whether the compression rate of the first file is less than or equal to a second threshold; if the compression rate of the first file is less than or equal to the second threshold, save the first file as the second file.
[0050] In combination with the second aspect, in certain implementations of the second aspect, the first file is a file of the target application, and the processing module is also used to: in response to the first input, before saving the first file as the second file, create a first database, the first database being used to store data information of the target application, and the data information of the target application includes the second file.
[0051] In combination with the second aspect, in some implementations of the second aspect, the first database includes first information, and the first information is used to indicate that data compression has been performed on the hole portion in the first file.
[0052] In combination with the second aspect, in some implementations of the second aspect, the acquisition module is further used to: send the second file to a cloud-side device, and the cloud-side device is used to store the second file.
[0053] In combination with the second aspect, in some implementations of the second aspect, the number of bytes of the first file is greater than or equal to a third threshold, the first file is composed of multiple third files, and the number of bytes of the third files is less than the third threshold.
[0054] According to a third aspect, an electronic device is provided, comprising a processor and a memory, wherein the memory is used to store program instructions, and the processor is used to: receive a first input; in response to the first input, save the first file as a second file when the first file includes a hole portion; wherein the first input is used to indicate performing data backup on the first file, the first file includes a hole portion and a data portion, the second file includes a target field and a data portion, and the target field is used to indicate a compression algorithm for performing data compression on the hole portion.
[0055] In combination with the third aspect, in some implementations of the third aspect, the second file includes a file block header and file block data, the file block header includes a target field, and the file block data includes a data portion.
[0056] In combination with the third aspect, in certain implementations of the third aspect, the file block header further includes a first field and a second field, the first field is used to indicate the number of bytes of the first file, and the second field is used to indicate the number of bytes of the data portion.
[0057] In combination with the third aspect, in some implementations of the third aspect, the file block header also includes a third field and / or a fourth field, the third field is used to identify the file block header, and the fourth field is used to indicate a file format version number of the second file.
[0058] In combination with the third aspect, in certain implementations of the third aspect, the file block header further includes a fifth field, and the fifth field is used to indicate an extended function supported by the second file.
[0059] In combination with the third aspect, in certain implementations of the third aspect, the processor is specifically used to: determine whether the file system of the electronic device supports the sparse file feature and whether the first file is a sparse file; if the file system of the electronic device supports the sparse file feature and the first file is a sparse file, save the first file as a second file.
[0060] In combination with the third aspect, in some implementations of the third aspect, the length of the hole portion is greater than or equal to a first threshold.
[0061] In combination with the third aspect, in certain implementations of the third aspect, the second file includes a file block header and file block data, the file block header includes a target field, the file block data includes a data part, the first threshold is the number of bytes of the file block header, and the processor is specifically used to: determine whether the length of the empty part is greater than or equal to the first threshold; if the length of the empty part is greater than or equal to the first threshold, save the first file as the second file.
[0062] In combination with the third aspect, in certain implementations of the third aspect, the processor is specifically used to: determine whether the compression rate of the first file is less than or equal to a second threshold; if the compression rate of the first file is less than or equal to the second threshold, save the first file as the second file.
[0063] In combination with the third aspect, in certain implementations of the third aspect, the number of bytes of the second file is less than or equal to the number of bytes of the first file.
[0064] In combination with the third aspect, in certain implementations of the third aspect, the first file is a file of the target application, and the processor is also used to: in response to the first input, before saving the first file as the second file, create a first database, the first database being used to store data information of the target application, and the data information of the target application includes the second file.
[0065] In combination with the third aspect, in some implementations of the third aspect, the first database includes first information, and the first information is used to indicate that data compression has been performed on the hole portion in the first file.
[0066] In combination with the third aspect, in certain implementations of the third aspect, the processor is further used to: send the second file to a cloud-side device, and the cloud-side device is used to store the second file.
[0067] In combination with the third aspect, in certain implementations of the third aspect, the number of bytes of the first file is greater than or equal to a third threshold, the first file is composed of multiple third files, and the number of bytes of the third files is less than the third threshold.
[0068] According to a fourth aspect, a computer program product is provided. The computer program product comprises a computer program code. When the computer program code is run on a computer, the method in the first aspect and any possible implementation manner thereof is executed.
[0069] In a fifth aspect, a computer-readable storage medium is provided, which stores a computer program code. When the computer program code runs on a computer, the method in the first aspect and any possible implementation thereof is executed.
[0070] In a sixth aspect, a chip is provided, comprising a processor for reading instructions stored in a memory, wherein when the processor executes the instructions, the chip implements the method in the first aspect and any possible implementation thereof. BRIEF DESCRIPTION OF THE DRAWINGS
[0071] Figure 1 It is a schematic diagram of the hardware architecture of an electronic device applicable to an embodiment of the present application.
[0072] Figure 2 It is a schematic diagram of the software architecture of an electronic device applicable to an embodiment of the present application.
[0073] Figure 3 It is a schematic diagram of the composition of the original file provided in the embodiment of the present application.
[0074] Figure 4 It is a schematic diagram of the composition of the compressed file provided in the embodiment of the present application.
[0075] Figure 5 It is a schematic diagram of a data compression method provided in an embodiment of the present application.
[0076] Figure 6 It is a schematic diagram of another data compression method provided in an embodiment of the present application.
[0077] Figure 7 and Figure 8 It is a schematic diagram of a graphical user interface of an electronic device provided in an embodiment of the present application.
[0078] Fig. 9 This is a schematic diagram of another data compression method provided in an embodiment of the present application.
[0079] Fig.10 This is a schematic diagram of another data compression method provided in an embodiment of the present application.
[0080] Fig.11 This is a schematic diagram of another data compression method provided in an embodiment of the present application.
[0081] Fig.12 and Fig.13 It is a schematic diagram of a graphical user interface of an electronic device provided in an embodiment of the present application.
[0082] Fig.14 It is a schematic diagram of a data compression device provided in an embodiment of the present application.
[0083] Fig.15 It is a schematic diagram of another data compression device provided in an embodiment of the present application.
[0084] Fig.16It is a schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0085] The technical solution in this application will be described below in conjunction with the accompanying drawings.
[0086] The terms used in the following embodiments are only for the purpose of describing specific embodiments, and are not intended to be used as limitations on the present application. As used in the specification and the appended claims of the present application, the singular expressions "one", "a kind of", "said", "above", "the" and "this" are intended to also include expressions such as "one or more", unless there is a clear contrary indication in the context. It should also be understood that in the following embodiments of the present application, "at least one", "one or more" refer to one, two or more. The term "and / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist; for example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship.
[0087] References to "one embodiment" or "some embodiments" etc. described in this specification mean that a particular feature, structure or characteristic described in conjunction with the embodiment is included in one or more embodiments of the present application. Thus, the phrases "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear at different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0088] The method provided in the embodiments of the present application can be applied to electronic devices such as mobile phones, tablet computers, wearable devices, vehicle-mounted devices, augmented reality (AR) / virtual reality (VR) devices, laptop computers, ultra-mobile personal computers (UMPCs), netbooks, personal digital assistants (PDAs), etc. The embodiments of the present application do not impose any restrictions on the specific types of electronic devices.
[0089] For example, Figure 11 shows a schematic diagram of the structure of the electronic device 100. The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0090] It is to be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0091] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0092] The controller may be the nerve center and command center of the electronic device 100. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.
[0093] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0094] In some embodiments, the processor 110 may include one or more interfaces. The interface may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.
[0095] It is understandable that the interface connection relationship between the modules illustrated in the embodiment of the present application is only a schematic illustration and does not constitute a structural limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.
[0096] The charging management module 140 is used to receive charging input from a charger. The charger may be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 may receive charging input from a wired charger through the USB interface 130. In some wireless charging embodiments, the charging management module 140 may receive wireless charging input through a wireless charging coil of the electronic device 100. While the charging management module 140 is charging the battery 142, it may also power the electronic device through the power management module 141.
[0097] The wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor and the baseband processor.
[0098] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of antennas. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch.
[0099] The mobile communication module 150 may provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to the electronic device 100. The mobile communication module 150 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc.
[0100] The wireless communication module 160 can provide wireless communication solutions including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc., which are applied to the electronic device 100. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, modulates the frequency of the electromagnetic wave signal and performs filtering, and sends the processed signal to the processor 110. The wireless communication module 160 can also receive the signal to be sent from the processor 110, modulate the frequency of it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.
[0101] The electronic device 100 implements the display function through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for image rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.
[0102] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device 100 may include 1 or N display screens 194, where N is a positive integer greater than 1.
[0103] The electronic device 100 can realize the shooting function through the ISP, the camera 193, the video codec, the GPU, the display screen 194 and the application processor. The ISP is used to process the data fed back by the camera 193. In some embodiments, the ISP can be set in the camera 193.
[0104] The camera 193 is used to capture still images or videos. In some embodiments, the electronic device 100 may include 1 or N cameras 193, where N is a positive integer greater than 1.
[0105] The digital signal processor is used to process digital signals, and can process not only digital image signals but also other digital signals. For example, when the electronic device 100 is selecting a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.
[0106] NPU is a neural-network (NN) computing processor. It can quickly process input information by drawing on the structure of biological neural networks, such as the transmission mode between neurons in the human brain, and can also continuously self-learn.
[0107] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function, such as storing music, video and other files in the external memory card.
[0108] The internal memory 121 may be used to store computer executable program codes, which include instructions. The processor 110 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121. The internal memory 121 may include a program storage area and a data storage area.
[0109] The electronic device 100 can implement audio functions such as music playing and recording through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone jack 170D, and the application processor.
[0110] The audio module 170 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. The audio module 170 can also be used to encode and decode audio signals. In some embodiments, the audio module 170 can be arranged in the processor 110, or some functional modules of the audio module 170 can be arranged in the processor 110.
[0111] The key 190 includes a power key, a volume key, etc. The key 190 may be a mechanical key or a touch key. The electronic device 100 may receive key input and generate key signal input related to user settings and function control of the electronic device 100.
[0112] The software system of the electronic device 100 may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present application takes the Android system of the layered architecture as an example to exemplify the software structure of the electronic device 100.
[0113] Figure 2 1 is a software structure diagram of the electronic device 100 of the embodiment of the present application. The layered architecture divides the software into several layers, each layer has a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom, namely, the application layer, the application framework layer, the Android runtime (Android runtime) and the system library, and the kernel layer. The application layer can include a series of application packages.
[0114] like Figure 2 As shown, the application package may include camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message and other applications.
[0115] The application framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions.
[0116] like Figure 2 As shown, the application framework layer may include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, and the like.
[0117] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, capture the screen, etc.
[0118] Content providers are used to store and retrieve data and make it accessible to applications. The data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
[0119] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images.
[0120] The phone manager is used to provide communication functions of the electronic device 100, such as management of call status (including connecting, hanging up, etc.).
[0121] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
[0122] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.
[0123] Android runtime includes core libraries and virtual machines. Android runtime is responsible for scheduling and management of the Android system.
[0124] The core library consists of two parts: one is the function that needs to be called by the Java language, and the other is the Android core library.
[0125] The application layer and the application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.
[0126] The system library may include multiple functional modules, such as surface manager, media libraries, 3D graphics processing library (such as OpenGL ES), 2D graphics engine (such as SGL), etc.
[0127] The surface manager is used to manage the display subsystem and provide the fusion of 2D and 3D layers for multiple applications.
[0128] The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
[0129] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.
[0130] A 2D graphics engine is a drawing engine for 2D drawings.
[0131] The kernel layer is the layer between hardware and software. The kernel layer contains at least display driver, camera driver, audio driver, and sensor driver.
[0132] It should be understood that the technical solutions in the embodiments of the present application can be used in Android, IOS, Hongmeng and other systems.
[0133] Before introducing the embodiments of the present application, some terms and definitions that may be used in the following content are first explained.
[0134] A sparse file is a computer file that attempts to use the file system's space more efficiently when the file's contents are mostly empty. It does this by representing empty data blocks with short information (metadata) instead of taking up actual space on the disk to store them. Only real (non-empty) data blocks are written to the disk as is. When reading a sparse file, the file system transparently converts these to "real" data blocks, i.e. filled with zeros, at runtime according to the metadata. The application is unaware of this conversion.
[0135] File hole, in UNIX file operations, the file offset can be greater than the current length of the file. In this case, the next write operation to the file will extend the file and form a hole in the file. Bytes that are in the file but have not been written are set to 0.
[0136] Data compression, also known as source coding, is the process of representing information using fewer data bits (or other information-related units) than the uncoded data according to a specific coding mechanism. The compression ratio is an indicator used to evaluate the results of data compression, which refers to the ratio of the amount of data after compression to the amount of data before compression.
[0137] The sparseness ratio refers to the ratio of the actual space occupied by a file to its logical size. The smaller the sparseness ratio, the higher the proportion of empty data blocks in the file, and the higher the efficiency of the sparse file.
[0138] File system, the computer file system is a method of storing and organizing computer data, which makes it easy to access and find it. The file system uses the abstract logical concept of files and tree directories instead of the concept of data blocks used by physical devices such as hard disks and optical disks. Strictly speaking, the file system is a set of abstract data types that implement operations such as data storage, hierarchical organization, access and retrieval.
[0139] Most modern file systems support the "sparse file" format, such as the Apple file system (APFS) and the fourth extended file system (ext4). On file systems that support the "sparse file" format, applications can choose to use the "sparse file" format for storage, storing only the content of the file that contains real data; on file systems that do not support the "sparse file" format, applications will store the entire content of the file.
[0140] Cloud backup refers to uploading the personal data on a user's device to a cloud device through backup, and supporting the user's device to restore personal data according to the backup record, so as to achieve the purpose of protecting the user's personal data. Here, the cloud device can be a server or a server cluster.
[0141] Data recovery is the process of rescuing deleted, inaccessible, lost, corrupted or formatted data from secondary storage, removable media or files when the data stored in the computer cannot be accessed in a conventional manner.
[0142] Data backup refers to saving files stored on electronic devices locally or on other storage media in a certain format and generating data backup records so that data can be restored using the backup data in the future when needed.
[0143] In some scenarios, users can save files on cloud-side devices, i.e., cloud backup. In some scenarios, users can also save files locally on electronic devices, i.e., local backup. In some scenarios, users can transfer backup files from electronic device A to electronic device B, and then restore them on electronic device B. For example, data synchronization between new and old electronic devices. The above scenarios all involve data backup and / or recovery. Due to the large number and variety of data that need to be backed up and / or restored, the data backup and / or recovery process often takes a long time and consumes more storage resources.
[0144] In order to improve the efficiency of electronic devices in performing data backup and / or recovery operations and reduce the storage resource occupation of storage devices, the present application provides a data compression method, which is now introduced as follows.
[0145] It should be noted that the following embodiments mainly use the cloud backup scenario to illustrate the data compression method provided by the present application. The corresponding data compression method in the scenario of local backup or data synchronization between electronic devices is not described in detail, and can be executed with reference to the content of the cloud backup scenario.
[0146] Figure 3 A schematic diagram of the composition of a first file 300 is provided by way of example. The first file 300 may also be referred to as an original file 300 or a file 300 before compression. The shaded portion in the figure represents real data 310 (or data portion 310) in the first file 300, and the blank portion represents a file hole 320 (or hole portion 320) in the first file 300.
[0147] The file hole refers to a portion of the first file 300 where disk space has been allocated but not filled with data, and the real data refers to a portion of the first file 300 that is filled with data.
[0148] In some examples, the file hole 320 may be generated when the electronic device downloads files in multiple threads at the same time. For example, the file hole 320 may be generated when a chat software (such as WeChat, QQ, etc.) on the electronic device shares a large file (such as a video file).
[0149] In some examples, the first file 300 may be a sparse file, and thus the file block header of the first file 300 may be defined in the same manner as the file block header of a sparse file.
[0150] Specifically, on a Linux system, the file block header of the first file 300 may be defined by a file system such as ext4 or an extended file system (XFS), and the file block header of the first file 300 may include the location and size information of valid data nodes of the file block data.
[0151] Figure 4 An exemplary schematic diagram of the composition of a second file 400 is provided. The second file 400 may be obtained by compressing the first file 300 using the data compression method provided in the present application.
[0152] The second file 400 may also be referred to as a target file 400 or a compressed file 400. The second file 400 may include a file block header 410 and file block data 420, wherein the file block header 410 may be used to indicate or describe one or more information of the compression algorithm of the first file 300, the size of the first file 300, and the size of the real data in the first file 300. The file block data 420 corresponds to the real data in the first file 300, or in other words, the content of the file block data 420 is the same as the content of the real data in the first file 300.
[0153] Table 1 shows a possible composition of a file block header 410. The file block header 410 may include one or more of the seven fields in the table.
[0154] Wherein, field #1 (or tag field) is used to indicate the identifier of the file block header 420. Field #2 (or version field) is used to indicate the version number of the file format.
[0155] Field #3 (or compression algorithm field) is used to indicate the compression algorithm used when compressing the first file 300. In some examples, the field #3 may include a compression algorithm, and the compression algorithm is used to indicate that only the file holes of the first file 300 are compressed. In some examples, the field #3 may include multiple compression algorithms, for example, the field #3 may include a first compression algorithm and a second compression algorithm, wherein the first compression algorithm may be used to indicate that the file holes of the first file 300 are compressed, and the second compression algorithm may be used to indicate that other types of data (e.g., picture data, etc.) of the first file 300 are compressed.
[0156] Field #4 (or the original data size field) is used to indicate the number of bytes of the first file 300 before compression, or the storage space occupied. Field #5 (or the target data size field) is used to indicate the number of bytes of the first file 300 after compression (i.e., the number of bytes of the real data contained in the first file 300), or the storage space occupied. Field #6 (or the extended area length field) is used to indicate the number of bytes of field #7, or the storage space occupied. Field #7 (or the extended area field) is used to indicate one or more extended functions supported by the compressed file format.
[0157] In some examples, the length of the file block header 420 may be 18+m bytes, where m is a positive integer. Among them, field #7 may occupy m bytes, or in other words, the length of field #7 is configured according to the actual compression process. For example, field #7 is used to indicate the implementation algorithm corresponding to the first extended function supported by the compressed file format, and the length of field #7 may be determined according to the length of the implementation algorithm corresponding to the first extended function.
[0158] In some examples, the lengths of field #1 to field #6 may be: 4 bytes, 2 bytes, 2 bytes, 4 bytes, 4 bytes, and 2 bytes, respectively.
[0159] Table 1 File block header format
[0160] Fields Starting position Number of bytes definition describe Field #1 0 4 tag File block header identifier Field #2 4 2 version File format version number Field #3 6 2 compression_algorithm Compression Algorithm Field #4 8 4 original_data_size Original data size Field #5 12 4 compressed_data_size Compressed size Field #6 16 2 expasion_area_length Extension area length Field #7 18 m expansion_area Extension Area
[0161] The compressed files can be used in a variety of scenarios such as file storage, data backup, and data transmission. Compared with the storage or transmission of uncompressed original files, in the file storage scenario, the compressed files can occupy a smaller storage space, which is conducive to improving the utilization efficiency of storage resources of storage devices. In the file transmission scenario, the compressed files take less time to send or receive, which is conducive to improving the file transmission efficiency.
[0162] Figure 5 A data compression method provided in an embodiment of the present application can compress file holes in a file by an electronic device. The compressed file occupies less storage space and has higher utilization efficiency of storage resources.
[0163] S510, receiving a first input.
[0164] In some examples, the first input is used to instruct to perform data backup on the first file. The first input may be one or more of voice input, touch input, gesture input, and the like.
[0165] In some examples, the first file may be a file containing a file hole, or may be a file not containing a file hole. Alternatively, the first file may be a file containing a file hole, but the contained file hole does not meet a preset requirement.
[0166] In some examples, the first file may include a file hole and real data, wherein the file hole refers to a portion of the first file where disk space has been allocated but not filled with data, and the real data refers to a portion of the first file filled with data.
[0167] In some examples, the first file may include only real data, or in other words, the first file may not include file holes.
[0168] In the scenario of performing data backup, the electronic device can create backup data in units of application programs.
[0169] In some examples, in response to the first input, the electronic device may create a first database, which may be used to store all data information of the target application that needs to be backed up. The first database may be used to record the files included in a backup record, and record the description information of the files, such as file type, file path, file size, file summary, etc., wherein the file summary may be used to verify the integrity of the downloaded data during data recovery.
[0170] The first database may include a second file obtained by compressing the first file. The first database may include first information, and the first information may be used to indicate that the file hole in the first file has been compressed.
[0171] For example, the first information may be identification information, for example, the first information may be a bit with a value of 1, and the value of the bit being 1 indicates that the file hole in the first file has been compressed.
[0172] In some examples, in response to the first input, the electronic device may create a first database, which may be used to store all data information of the target application that needs to be backed up. The first database may be used to record the files included in a backup record, and record the description information of the files, such as file type, file path, file size, file summary, etc., wherein the file summary may be used to verify the integrity of the downloaded data during data recovery.
[0173] The first database may include a first file that does not contain a file hole, or the first database may include a first file that is not compressed. The first database may include first information, and the first information may be used to indicate that a file hole in the first file is not compressed, or the first information may be used to indicate that the first file is not compressed.
[0174] For example, the first information may be identification information, for example, the first information may be a bit with a value of 0. The value of the bit being 0 indicates that the file hole in the first file is not compressed.
[0175] S520: Determine whether there is a file hole in the first file.
[0176] In some examples, the first file may be a file known to have a file hole, for example, the first file is a data file of a target application, and the use of the target application generates a file containing a file hole. For such a first file, the electronic device may directly compress the file hole contained therein.
[0177] In some examples, the electronic device needs to determine whether the first file contains a file hole.
[0178] In some examples, in response to the first input, the electronic device may determine whether a file system of the electronic device supports a sparse file characteristic, and determine whether the first file is a sparse file.
[0179] The file system of the electronic device supports the sparse file feature, which can also be understood as the file system of the electronic device supports sparse files or supports sparse file formats. It can mean that the file system of the electronic device has all or part of the functions that rely on sparse files, including but not limited to: reading sparse files, creating sparse files, writing new data in sparse files, etc.
[0180] A sparse file can be considered as a file containing a file hole. Taking the Linux system as an example, the file header of a sparse file is defined by a file system such as ext4 or XFS. The electronic device can determine whether the first file is a sparse file by reading information in the file header of the sparse file.
[0181] In a subsequent compression process, the electronic device may compress the sparse file.
[0182] If the first file is not a sparse file, or the file system of the electronic device does not support the sparse file feature, the electronic device may not compress it and directly perform corresponding processing operations based on the original file. The electronic device may also determine whether there is a file hole in the first file by searching whether there is space in the first file that has been allocated disk space but not filled with actual data.
[0183] In the subsequent compression process, the electronic device may compress the file holes in the retrieved first file.
[0184] In the case where there is no file hole in the first file, or in other words, the electronic device has not retrieved the file hole in the first file, the electronic device can directly perform corresponding processing operations based on the original file.
[0185] A file hole can be regarded as all-zero data of a certain length. Generally, whether a file contains a file hole can be determined by searching whether there is all-zero data in the file.
[0186] In order to improve the efficiency of electronic devices in searching for file holes and shorten the time spent on compressing the first file, in some examples, the electronic device can determine whether there is a file hole that meets the preset conditions in the first file by searching whether there is all-zero data greater than or equal to a preset length in the first file. In the subsequent compression process, the electronic device can only compress the file holes that meet the preset conditions. Since the file holes that do not meet the preset conditions are filtered out during the retrieval process, the electronic device may not compress the file holes that do not meet the preset conditions in the subsequent compression process.
[0187] S530: When there is a file hole in the first file, compress the file hole.
[0188] In some examples, when a file hole exists in the first file, the electronic device may compress the file hole in the first file.
[0189] The second file represents the compressed file, and the second file may include a target field and real data, wherein the target field is used to indicate the compression algorithm for compressing the file hole in the first file, such as field #3 in Table 1. The content of the real data is consistent with the content of the real data in the first file.
[0190] In some examples, the second file may be divided into a file block header and file block data, wherein the file block header may include the aforementioned target field, and the file block data may include real data.
[0191] In some examples, the file block header of the second file may include a first field and a second field, the first field is used to indicate the number of bytes of the first file, and the second field is used to indicate the number of bytes of the real data. Exemplarily, the first field may be field #4 in Table 1, and the second field may be field #5 in Table 1.
[0192] In some examples, the file block header of the second file may include a third field and / or a fourth field, the third field is used to identify the file block header, and the fourth field is used to indicate the file format version number of the second file. Exemplarily, the third field may be field #1 in Table 1, and the fourth field may be field #2 in Table 1.
[0193] In some examples, the file block header of the second file may include a fifth field, and the fifth field may be used to indicate an extended function supported by the second file. Exemplarily, the fifth field may be field 7 in Table 1.
[0194] The file block header of the second file may also include more fields besides the above fields, such as field 6 in Table 1.
[0195] According to the above data compression method, compared with the first file, the second file compresses the file holes but adds the file block header. In order to reduce the storage resource occupation of the compressed second file, the electronic device can determine whether to compress the file holes of the first file based on the relative size of the second file and the first file.
[0196] Specifically, if the number of bytes in the second file is less than or equal to the number of bytes in the first file, the second file is compressed; if the number of bytes in the second file is greater than the number of bytes in the first file, the second file is not compressed. In other words, if the number of bytes in the file block header of the second file is less than or equal to the number of bytes in the file hole in the first file, the second file is compressed; if the number of bytes in the file block header of the second file is greater than the number of bytes in the file hole in the first file, the second file is not compressed.
[0197] In the process of compressing the first file to form the second file, not only storage resources are required, but also certain computing resources are required. If there are fewer holes in the first file, or if the real data in the first file accounts for a higher proportion, the storage resources that can be saved by the second file after compression are limited, and the computing resources occupied during the compression process may be relatively large.
[0198] In view of the above situation, it may be considered to perform file hole compression on the first file whose file hole ratio is greater than a certain threshold, and not perform file hole compression on the first file whose file hole ratio is less than the threshold.
[0199] The compression ratio or sparsity ratio can be used to indicate the proportion of real data in a file, and can be calculated by the ratio of the space occupied by the real data to the space occupied by the file.
[0200] The above scheme can also be understood as performing file hole compression on the first file when the compression rate of the first file is less than or equal to a certain threshold; and not performing file hole compression on the first file when the compression rate of the first file is greater than the aforementioned threshold.
[0201] In some scenarios, an electronic device needs to process multiple first files, and the number of bytes of the first files is relatively small. The process of compressing the multiple first files separately occupies more computing resources of the electronic device. In order to improve the efficiency of the electronic device in compressing files containing file holes, the multiple first files can be taken as a set and compressed and processed uniformly after being packaged.
[0202] In some instances, when the number of bytes of the first file is less than a third threshold, multiple first files are obtained so that the sum of the number of bytes of the multiple first files is greater than or equal to the third threshold, and then the multiple first files are regarded as a whole to compress file holes.
[0203] S540, processing the compressed first file, that is, the second file.
[0204] After executing the data compression operation in S530, the electronic device may perform a series of processing operations on the second file.
[0205] For example, in a data backup scenario, the electronic device can send the second file to a cloud device and other storage devices to perform a data backup of the first file. Alternatively, the electronic device can also directly save the compressed file on a local storage medium of the electronic device. Since the number of bytes of the second file is reduced relative to the number of bytes of the first file after the file hole is compressed, it takes less time to send the second file, and the storage resources occupied by storing the second file are less, and the utilization efficiency of storage resources is higher.
[0206] S550: directly process the first file without compressing the first file.
[0207] When the first file does not include a file hole, or when the first file does not include a file hole that meets a preset condition, the electronic device may not compress the first file, but directly perform corresponding processing operations on the first file.
[0208] In the data backup scenario, the electronic device may directly send the first file to the cloud device and / or other storage devices. Alternatively, the electronic device may also directly store the first file on a local storage medium of the electronic device.
[0209] The electronic device can determine the files that need to be compressed based on different judgment conditions, and can also execute different file compression methods under different circumstances (for example, storage resources and computing resources have different limitations). The data compression method provided by the present application can improve the utilization efficiency of the storage resources of the storage device, which is conducive to improving the utilization efficiency of the computing resources of the electronic device, and improve the efficiency of data backup and recovery in the data backup scenario.
[0210] Figure 6 This is another data compression method provided by an embodiment of the present application. An electronic device can detect and compress file data stored in a sparse file format.
[0211] S610, receiving a first input, and executing a cloud backup operation in response to the first input of a user.
[0212] In order to protect the personal data on the electronic devices used by users, users can use the cloud backup software installed on the electronic devices to initiate cloud backup and back up local personal data to the cloud-side device. In the event of virus intrusion, human error deletion, data corruption, hardware failure or device replacement, the user's personal data can be restored from the cloud-side device.
[0213] In some examples, the electronic device may receive a first input from a user, and in response to the first input, the electronic device performs a cloud backup operation. The first input may be an input acting on a first application, and the first application is used to perform the cloud backup operation. In other words, in response to the user's operation on the first application, the electronic device performs the cloud backup operation.
[0214] Figure 7 A user interface 700 of a first application (hereinafter referred to as the first interface 700) is exemplarily provided, and the first application may also be called a cloud backup application. The first interface 700 may include a first control 710, and the aforementioned first input may be an input to the first control 710.
[0215] It should be noted that the first input may be one or more of a user's touch input, voice input, or gesture input, and this application does not impose any limitation on this.
[0216] In response to the user's first input, the electronic device can create a first database, which can be used to record all data information of the target application that needs to be backed up. The first database can be used to record the files included in a backup record, and record the description information of the files, such as: file type, file path, file size, file summary, etc., wherein the file summary can be used to verify the integrity of the downloaded data during the data recovery process.
[0217] S620: Determine whether the file system of the electronic device supports a “sparse file” feature.
[0218] In some examples, the first application may determine whether the file system of the electronic device supports a “sparse file” feature by calling a system API.
[0219] Taking the Linux system as an example, the first application can use the fallocate function to allocate storage space without actually writing data. If the return value of the fallocate function is 0, it is determined that the file system of the electronic device supports the "sparse file" feature. If the return value of the fallocate function is non-zero, it is determined that the file system of the electronic device does not support the "sparse file" feature.
[0220] S630: When the file system of the electronic device supports the “sparse file” feature, determine whether the original file to be backed up is a sparse file.
[0221] In some examples, on a Linux system, the first application may obtain file information through a stat function, and determine whether the original file is a sparse file based on the file information.
[0222] Exemplarily, the file information may include: the block size of the file (st_blksize), the number of disk blocks occupied by the file (st_blocks), and the actual size of the file (st_size). If the product of the block size of the file and the number of disk blocks occupied by the file is less than the actual size of the file, it means that the original file is a sparse file, otherwise, the original file is not a sparse file.
[0223] S640: If the file system of the electronic device supports the “sparse file” feature and the original file to be backed up is a sparse file, compress the original file.
[0224] Taking the Linux system as an example, the file header of a sparse file is defined by a file system such as ext4 or XFS. In the file system, each file has an inode structure, which contains the file's metadata information, including the file's size, permissions, and creation time. For sparse files, the st_blocks field in the inode structure indicates the number of disk blocks occupied by the file, and the st_size field indicates the actual size of the file.
[0225] When reading the data part and the empty part of a sparse file, you can use the system call read() function or pread() function to read the contents of the file. The lseek() function can be used to skip the empty part of the sparse file and then read the data part.
[0226] After all valid data nodes are read, they are written into the target file according to the file blocks. The header area of the file block marks the location and size information of the valid data nodes, and the actual data is written into the data area of the file block. After the loop completes the writing of all valid data nodes, the file compression is completed.
[0227] Specifically, the structure of the original file can be as follows Figure 3 As shown, the structure of the compressed file can be as follows Figure 4 The following steps are used to read the data part and the hole part of the sparse file.
[0228] 1) Open the original file and obtain the inode structure information of the file, including the file size and the number of disk blocks occupied.
[0229] 2) Use the lseek() function to skip the empty part in the original file, that is, move the file pointer to the next non-empty position, and record the file block header information according to the pointer position information. The sum of the real data of the original file and the size of the empty data is recorded in field #4 of the file block header of the compressed file, and the size of the real data of the original file is recorded in field #5 of the file block header of the compressed file.
[0230] Field #3 of the file block header of the compressed file can be used to record the identifier of the first compression algorithm (for example, the name of the compression algorithm). According to the identifier of the first compression algorithm, it can be determined that the compressed file is obtained by compressing the empty part of the file.
[0231] 3) Use the read() function or pread() function to read the real data part of the original file and write it into the file block data of the compressed file.
[0232] 4) Loop through steps 2) and 3) above, that is, read data starting from the location of the file pointer until the number of bytes read reaches the file size.
[0233] S650, upload the compressed original file to the cloud side device.
[0234] The electronic device may upload the compressed file obtained by compression in S640 to the cloud-side device.
[0235] In some examples, after the file is uploaded to the cloud side device, the file compression type and cloud side file information are recorded and updated to the aforementioned first database. In the data recovery scenario, the data received from the cloud side device can be decompressed according to the compression type in the first database.
[0236] S660, when the file system of the electronic device does not support the "sparse file" feature, or when the file system of the electronic device supports the "sparse file" feature but the original file to be backed up is not a sparse file, the original file is uploaded to the cloud side device.
[0237] In some examples, when the file system of the electronic device does not support the "sparse file" feature, the first application reads the original file and uploads it to the cloud-side device. In this case, the compression type of the original file can be marked as "no compression" in the first database, or the compression type of the original file can be marked as "0" to indicate that the metadata stores the original file.
[0238] In some examples, when the file system of the electronic device supports the "sparse file" feature, but the original file to be backed up is not a sparse file, the first application reads the original file and uploads it to the cloud-side device. In this case, the compression type of the original file can be marked as "no compression" in the first database, or the compression type of the original file can be marked as "0" to indicate that the original file is stored in the metadata.
[0239] S670, obtaining cloud services. S670 is an optional step.
[0240] For the backup data saved in the cloud-side device, the user can manage and use the data through the first application. Figure 8 A user interface 800, or second interface 800, for an electronic device to manage backup data is exemplarily provided.
[0241] The second interface 800 may display one or more backup data stored in the cloud-side device. In some examples, the second interface 800 may include a second control 810, a third control 820, and a fourth control 830. The second control 810 is used to display an entry for restoring the backup data. In some examples, in response to a user selecting the second control 810, the electronic device may display a third user interface, which may be used to display one or more data backup records, and in response to a user selecting a data backup record, the electronic device may restore the selected backup data.
[0242] The third control 820 may include one or more tabs. In some examples, the one or more tabs may be used to indicate one or more backup data. For example, the first tab is used to indicate system data, the second tab is used to indicate data of the "Contacts" application, and the third tab is used to indicate data of the "Music" application. In response to the operation of the one or more tabs, the electronic device may perform processing such as displaying and deleting the backup data corresponding to the tab.
[0243] The fourth control 830 can be used to indicate a "delete and close backup" function. In response to selecting the fourth control 830, the electronic device can send a request to delete data to the server to delete the backup data stored on the server. In response to selecting the fourth control 830, the electronic device can also close the cloud backup function.
[0244] Based on the data that has been backed up, the electronic device can also obtain other cloud services other than the above-mentioned data management services through the server, which will not be elaborated here.
[0245] Fig. 9This is another data compression method provided by an embodiment of the present application. In this embodiment, the electronic device can not only compress sparse files, but also compress file holes in non-sparse files.
[0246] S910, receiving a first input, and executing a cloud backup operation in response to the first input of a user.
[0247] In some examples, the electronic device may receive a first input from a user, and in response to the first input, the electronic device performs a cloud backup operation. The first input may be an input acting on a first application, and the first application is used to perform the cloud backup operation. In other words, in response to the user's operation on the first application, the electronic device performs the cloud backup operation.
[0248] The relevant content of the first input is similar to that in S610 , and for details, please refer to the relevant description in S610 . For the sake of brevity, it will not be repeated here.
[0249] S920: Determine whether the file system of the electronic device supports a “sparse file” feature.
[0250] In some examples, the first application may determine whether the file system of the electronic device supports a “sparse file” feature by calling a system API.
[0251] For specific details, please refer to the relevant contents in S620. For the sake of brevity, they will not be elaborated here.
[0252] S930: When the file system of the electronic device supports the sparse file feature, determine whether the original file is in a sparse file format.
[0253] In some examples, on a Linux system, the first application may obtain file information through a stat function, and determine whether the original file is a sparse file based on the file information.
[0254] For specific details, please refer to the relevant content in S630. For the sake of brevity, it will not be repeated here.
[0255] S940: If the file system of the electronic device supports a sparse file feature and the original file is in a sparse file format, compress the sparse file.
[0256] The structure of the original file can be as follows Figure 3 As shown, the structure of the compressed file can be as follows Figure 4 The method for compressing the sparse file is similar to the related content in S640. For the specific content, please refer to the related content in S640. For the sake of brevity, it will not be described here.
[0257] S950: Determine whether there is a file hole in the original file.
[0258] In some examples, when the file system of the electronic device does not support the sparse file feature, it is determined whether there is a file hole in the original file.
[0259] In some examples, when the file system of the electronic device supports a sparse file feature and the original file is not in a sparse file format, it is determined whether the original file has a file hole.
[0260] In some examples, the electronic device may determine the file holes in the original file by detecting the "0" bit in the original file. Accordingly, the data between two adjacent file holes is the real data.
[0261] A file hole can be regarded as all-zero data of a certain length. Generally, whether a file contains a file hole can be determined by searching whether there is all-zero data in the file. In some examples, in order to improve detection efficiency, data with a length of consecutive "0" bits greater than or equal to a preset length is determined to be a file hole, and data with a length of consecutive "0" bits less than a preset length is determined not to be a file hole.
[0262] Exemplarily, the preset length may be the length of the file block header of the compressed file. For example, the length of the compressed file block header shown in Table 1 is 18+m, where m is the length of the extension area and m is a positive integer. In this case, the technical solution may also be understood as compressing the file holes in the original file for the original file whose length after compression is less than or equal to the length of the original file; and not compressing the file holes in the original file for the original file whose length after compression is greater than the length of the original file.
[0263] Specifically, whether the length of the file hole in the original file is greater than or equal to a preset length may be determined through the following detection steps.
[0264] 1) Read the file content in a loop and perform a full 0 value match with n bytes as a sliding window (n is a positive integer). If the match is successful, it is recorded as a file hole area, and the starting position of the area is the starting position of the sliding window;
[0265] 2) If the length of the sliding window + 1 character is still 0, continue matching until a non-zero byte is found, at which point the end position of the file hole is determined.
[0266] 3) Through steps 1) and 2), a continuous file hole is found, and the starting position (file offset, offset value) and the hole length are recorded. The loop is executed until the end of the file to detect all the file holes in the original file.
[0267] S960, upload the compressed original file to the cloud side device.
[0268] In some examples, when the file system of the electronic device supports a sparse file feature and the original file is in a sparse file format, a first compressed file obtained by compressing the original file is uploaded to a cloud-side device.
[0269] In some examples, when there is a file hole in the original file, the electronic device compresses the file hole in the original file to obtain a second compressed file, and uploads the second compressed file to the cloud-side device.
[0270] The method for compressing a file hole may perform compression according to the starting position and length of the file hole determined in S950. In some examples, the file hole in the original file may be compressed according to the following steps.
[0271] 1) If the starting position of the file hole is 0, the size of the original file recording the Nth file block (i.e., the value of field #4 in Table 1) is the hole length, and the size of the compressed file (i.e., the value of field 5 in Table 1) is 0, where N is a positive integer.
[0272] 2) If the starting position of the file hole is not 0, the size of the original file recording the Nth file block is the starting position of the Nth file hole (file offset value) + the hole length; the size of the compressed file is the starting position of the Nth file hole.
[0273] 3) The size of the original file of the N+1th compressed file block can be calculated based on the end position of the N+1th file hole minus the end position of the Nth file hole; the size of the compressed file of the N+1th compressed file block can be calculated based on the size of the original file minus the length of the N+1th file hole.
[0274] 4) Similarly, the header description information of each file block and the real data information can be obtained and written into the new file at once to complete the compression process. The file saving format is the same as that shown in Table 1.
[0275] In some examples, S950 and S960 can be executed synchronously, that is, the electronic device can compress the original file while detecting the hole part in the original file, so as to complete the detection and compression process by reading the file once, thereby improving the file detection and compression efficiency.
[0276] It should be noted that the electronic device simultaneously detecting and compressing the original file may refer to detecting a first file contained in the original file and compressing a second file contained in the original file. Alternatively, the electronic device simultaneously detecting and compressing the original file may refer to detecting a first part contained in the original file and compressing a second part contained in the original file.
[0277] S970: When there is no file hole in the original file, upload the original file to the cloud-side device.
[0278] If the electronic device does not support the sparse file feature, or the electronic device supports the sparse file feature but the original file does not belong to the sparse file format, the electronic device can determine whether there is a file hole in the original file, and directly upload the original file to the cloud side device if it is determined that there is no file hole in the original file.
[0279] In this case, the compression type of the original file may be marked as "no compression" in the first database, or the compression type of the original file may be marked as "0" to indicate that the original file is stored in the metadata.
[0280] S980: Obtain cloud service. S980 is an optional step.
[0281] For the backup data saved in the cloud side device, the user can manage and use the data through the first application. The content related to the cloud service is similar to the related description in S670, and is not repeated here for the sake of brevity.
[0282] Fig.10 This is another data compression method provided by an embodiment of the present application. In this embodiment, the electronic device can determine whether to compress the original file based on the sparsity rate of the original file so that the storage resources occupied by the compressed file can be reduced relative to the original file.
[0283] S1010, receiving a first input, and executing a cloud backup operation in response to the first input of a user.
[0284] In some examples, the electronic device may receive a first input from a user, and in response to the first input, the electronic device performs a cloud backup operation. The first input may be an input acting on a first application, and the first application is used to perform the cloud backup operation. In other words, in response to the user's operation on the first application, the electronic device performs the cloud backup operation.
[0285] The relevant content of the first input is similar to that in S610 , and for details, please refer to the relevant description in S610 . For the sake of brevity, it will not be repeated here.
[0286] S1020, determining whether the file system of the electronic device supports a “sparse file” feature.
[0287] In some examples, the first application may determine whether the file system of the electronic device supports a “sparse file” feature by calling a system API.
[0288] For specific details, please refer to the relevant contents in S620. For the sake of brevity, they will not be elaborated here.
[0289] S1030: When the file system of the electronic device supports the sparse file feature, determine whether the original file is in a sparse file format.
[0290] In some examples, on a Linux system, the first application may obtain file information through a stat function, and determine whether the original file is a sparse file based on the file information.
[0291] For specific details, please refer to the relevant content in S630. For the sake of brevity, it will not be repeated here.
[0292] S1040, determining whether there is a file hole in the original file.
[0293] In some examples, when the file system of the electronic device does not support the sparse file feature, it is determined whether there is a file hole in the original file.
[0294] In some examples, when the file system of the electronic device supports a sparse file feature and the original file is not in a sparse file format, it is determined whether the original file has a file hole.
[0295] The method for determining whether there is a file hole in the original file is similar to the related description in S1050, and is not repeated here for the sake of brevity.
[0296] S1050: Determine whether the sparseness rate of the original file is less than or equal to a preset value.
[0297] In some examples, when the file system of the electronic device supports a sparse file feature and the original file is in a sparse file format, it is determined whether the sparse rate of the original file is less than or equal to a preset value.
[0298] For the original file in sparse file format, the system API can be used to read the storage information of the file block, and then obtain the real data and the size of the file hole, so as to calculate the sparsity rate (or compression rate). The formula is as follows:
[0299]
[0300] Among them, p1 represents the sparseness rate or compression rate, M aIndicates the size of the real data in the original file, M h Indicates the size of the holes in the original file.
[0301] In some examples, when a file hole exists in the original file, it is determined whether the sparseness rate of the original file is less than or equal to a preset value.
[0302] Taking the Linux system as an example, by using the stat function to obtain the file information, the sparseness rate or compression rate of the original file can be calculated. The calculation formula is as follows:
[0303]
[0304] Where p2 represents the sparsity rate or compression rate; M b Indicates the block size of the file, M b The value of can be determined by using the stat function to obtain st_blksize; B represents the number of disk blocks occupied by the original file, and the value of B can be determined by using the stat function to obtain st_blocks. f Indicates the actual size of the original file, M f The value can be determined by using the stat function to obtain st_size.
[0305] S1060, upload the compressed original file to the cloud-side device.
[0306] When the sparseness rate of the original file is less than a preset value, the compressed original file is uploaded to the cloud-side device.
[0307] S1070, upload the original file to the server.
[0308] In some examples, when there is no file hole in the original file, the original file is uploaded to the cloud-side device.
[0309] In some examples, when the sparseness rate of the original file is greater than a preset value, the original file is uploaded to the cloud-side device.
[0310] If the sparseness rate in the original file is less than the preset value, it means that there are fewer file holes in the original file. In this case, the original file can be directly uploaded to the server.
[0311] S1080, get cloud services.
[0312] For the backup data saved in the cloud side device, the user can manage and use the data through the first application. The content related to the cloud service is similar to the related description in S670, and is not repeated here for the sake of brevity.
[0313] Fig.11A data recovery method provided by an embodiment of the present application is shown. In this method, the electronic device can determine the compression method of the file data according to the file block header of the compressed file, and then decompress the compressed data to achieve the recovery of the backup data.
[0314] S1110 , receiving a second input, and executing a data recovery operation in response to the second input of the user.
[0315] The backup data can be used to restore the user's personal data in the event of a virus attack, human error, data corruption, hardware failure, or device replacement on the user's electronic device. The backup data here can be data stored in one or more of a cloud device, an electronic device, or other storage media (e.g., other electronic devices).
[0316] In some examples, the electronic device may receive a second input from a user, and in response to the second input, the electronic device performs a data recovery operation. The second input may be an input acting on a second application, and the second application is used to perform the data recovery operation. In other words, in response to the user's operation on the second application, the electronic device performs the data recovery operation.
[0317] Fig.12 A user interface 1200 (hereinafter referred to as the third interface 1200) of a second application is exemplarily provided, and the third interface 1200 may include a fifth control 1210, and the fifth control 1210 may include one or more backup records. In response to the user selecting any of the one or more backup records, the electronic device may display the following Fig.13 The recovery data selection interface (hereinafter referred to as the fourth interface 1300) is shown.
[0318] In some examples, the third interface 1200 may also display backup records of other electronic devices besides the current electronic device.
[0319] The third interface 1200 may further include a sixth control 1220 . In response to an operation on the sixth control 1220 , the electronic device may display all backup records on the third interface 1200 .
[0320] The fourth interface 1300 may include a seventh control 1310, which may be used to display detailed information in the backup data indicated by the backup record selected by the user, for example, data of different applications included in the backup data indicated by the backup record. In response to the user selecting the data of one or more applications in the seventh control 1310, the electronic device may determine that the data of the application selected by the user needs to perform a data recovery operation, and the data of the application not selected by the user does not need to perform a data recovery operation.
[0321] In some examples, the fourth interface 1300 may further include an eighth control 1320 , and in response to a user selecting the eighth control 1320 , the electronic device may perform a recovery operation on the data of the application selected by the user.
[0322] In some examples, the aforementioned first application and the second application may be the same application, or in other words, the data backup function and the data recovery function of the electronic device may be integrated into the same application (ie, implemented through the same application).
[0323] S1120, reading metadata and determining a decompression algorithm.
[0324] As mentioned above, the backup data of the electronic device may be uncompressed data (i.e., the original file), or may be data obtained by compressing the file holes in the original file. The electronic device may determine the type of backup data by reading metadata. For example, the electronic device may read the data compression type information in the metadata, and when the compression type is 0, determine that the current backup data is the original file, or uncompressed data. When the compression type is not 0, determine that the current backup data is a compressed file.
[0325] S1130, decompress the file according to the compression algorithm.
[0326] In the case where the current backup data is an original file, the electronic device can directly write the backup file to the corresponding file address. For example, the electronic device can perform matching based on the application name of the application data in the backup data, and write the application data in the backup data to the address where the data of the application corresponding to the application data is stored. For example, the data belonging to application A in the backup data is written to the address where the application data of application A is stored on the electronic device.
[0327] In the case where the current backup data is a compressed file, the electronic device can read the file block header of the file data to determine the compression algorithm of the compressed file, thereby determining the decompression algorithm corresponding to the compression algorithm. Using the decompression algorithm, the electronic device can decompress the compressed file into the original file. After obtaining the original file, the electronic device writes the original file to the corresponding address.
[0328] S1140, data recovery is completed.
[0329] After executing all the application data in the backup data, the electronic device completes data recovery. It should be noted that if the electronic device does not have the application corresponding to the application data in the backup data installed locally, the electronic device can perform data recovery after installing the application.
[0330] Based on similar principles, Fig.14 As shown, the embodiment of the present application further provides a data compression device 1400 , which includes a backup function module 1410 , a recovery function module 1420 and a file system 1430 .
[0331] Among them, the backup function module 1410 may include a backup submodule 1411, a file upload submodule 1412, a sparse file detection submodule 1413, a detection strategy control submodule 1414, a compression strategy control submodule 1415 and a sparse file compression submodule 1416.
[0332] The backup submodule 1411 is used to control the backup process and implement the backup business; the file upload submodule 1412 is used to upload the compressed file or the original file to the cloud-side device; the sparse file detection submodule 1413 is used to detect the sparse file format; the detection strategy control submodule 1414 is used to control the detection strategy, for example, setting the detection conditions for detecting a certain file type, etc.; the compression strategy control submodule 1415 is used to control different compression strategies, for example, setting the version of the compression function and the compression rate threshold, etc.; the sparse file compression submodule 1416 is used to compress sparse files according to the compression strategy.
[0333] The recovery function module 1420 may include a recovery submodule 1421 , a file download submodule 1422 , and a file decompression submodule 1423 .
[0334] The recovery submodule 1421 is used to control the recovery process and implement the recovery business; the file download submodule 1422 is used to download the files waiting to be restored from the cloud device storage according to the backup records selected by the user; the file decompression submodule 1423 is used to decompress the specified file according to the compression mark described in the file metadata.
[0335] Fig.15 Another data compression device 1500 provided in an embodiment of the present application is shown. The data compression device 1500 may have the functions of the electronic device in the above method embodiment, and may be used to execute the steps performed by the functions of the electronic device in the above method embodiment. The functions may be implemented by hardware, or by software or hardware executing corresponding software implementations. The hardware or software includes one or more modules corresponding to the above functions.
[0336] In a possible implementation, the data compression device 1500 may include an acquisition module 1510 and a processing module 1520, and the acquisition module 1510 and the processing module 1520 are coupled to each other.
[0337] The acquisition module 1510 can be used to support the electronic device to obtain the user's input. The acquisition module 1510 can also be used to support the electronic device to communicate, such as executing Figure 5 The actions of receiving user input and sending data to the cloud-side device and / or receiving data from the cloud-side device.
[0338] The processing module 1520 is used to support the electronic device to execute the processing actions in the above method embodiments, such as the processing actions executed by the electronic device such as file holes in compressed files.
[0339] Optionally, the data compression device 1500 may further include a storage unit 1530 for storing program codes and data of the data compression device 1500 .
[0340] Fig.16 An electronic device 1600 provided in an embodiment of the present application, as shown in the figure, includes: at least one processor 1610 and a transceiver 1620. The processor 1610 is coupled to a memory and is used to execute instructions stored in the memory to control the transceiver 1620 to send and / or receive signals.
[0341] Optionally, the electronic device 1600 further includes a memory 1630 for storing instructions.
[0342] In some embodiments, the processor 1610 and the memory 1630 may be combined into a processing device, and the processor 1610 is used to execute the program code stored in the memory 1630 to implement the above functions. In specific implementation, the memory 1630 may also be integrated into the processor 1610, or independent of the processor 1610.
[0343] In some embodiments, the transceiver 1620 may include a receiver (or receiver) and a transmitter (or transmitter).
[0344] The transceiver 1620 may further include an antenna, and the number of antennas may be one or more. The transceiver 1620 may be a communication interface or an interface circuit.
[0345] When the electronic device 1600 is a chip, the chip includes a transceiver module and a processing module, wherein the transceiver module may be an input / output circuit or a communication interface; and the processing module may be a processor or a microprocessor or an integrated circuit integrated on the chip.
[0346] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0347] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0348] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0349] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0350] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0351] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned storage media include: various media that can store program codes, such as USB flash drives, mobile hard disks, read-only memories (ROM), random access memories (RAM), magnetic disks or optical disks.
[0352] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A method for data compression, characterized in that: Used in electronic equipment, including: receiving a first input; In response to the first input, if the first file includes a hole portion, saving the first file as a second file; The first input is used to indicate data backup of the first file, the first file includes a data part and the hole part, the second file includes a target field and the data part, and the target field is used to indicate a compression algorithm for data compression of the hole part.
2. The method according to claim 1, characterized in that The second file includes a file block header and file block data, the file block header includes the target field, and the file block data includes the data portion.
3. The method according to claim 2, characterized in that The file block header further includes a first field and a second field, wherein the first field is used to indicate the number of bytes of the first file, and the second field is used to indicate the number of bytes of the data portion.
4. The method according to claim 3, characterized in that The file block header further includes a third field and / or a fourth field, the third field is used to identify the file block header, and the fourth field is used to indicate a file format version number of the second file.
5. The method according to any one of claims 2 to 4, characterized in that The file block header also includes a fifth field, and the fifth field is used to indicate an extended function supported by the second file.
6. The method according to any one of claims 1 to 5, characterized in that In response to the first input, when the first file includes a hole portion, saving the first file as a second file comprises: Determining whether the file system of the electronic device supports a sparse file feature and whether the first file is a sparse file; When the file system of the electronic device supports a sparse file feature and the first file is a sparse file, the first file is saved as the second file.
7. The method according to any one of claims 1 to 6, characterized in that The length of the hole portion is greater than or equal to a first threshold.
8. The method according to claim 7, characterized in that The second file includes a file block header and file block data, the file block header includes the target field, the file block data includes the data portion, the first threshold is the number of bytes of the file block header, In response to the first input, when the first file includes a hole portion, saving the first file as a second file comprises: Determine whether the length of the hole portion is greater than or equal to the first threshold; When the length of the hole portion is greater than or equal to the first threshold, the first file is saved as the second file.
9. The method according to any one of claims 1 to 8, characterized in that In response to the first input, when the first file includes a hole portion, saving the first file as a second file comprises: Determining whether the compression ratio of the first file is less than or equal to a second threshold; If the compression rate of the first file is less than or equal to a second threshold, the first file is saved as a second file.
10. The method according to any one of claims 1 to 9, characterized in that The first file is a file of a target application. Before saving the first file as a second file in response to the first input, the method further includes: A first database is created, where the first database is used to store data information of the target application, where the data information of the target application includes the second file.
11. The method according to claim 10, characterized in that The first database includes first information, where the first information is used to indicate that data compression has been performed on the hole portion.
12. The method according to any one of claims 1 to 11, characterized in that The method further comprises: The second file is sent to a cloud-side device, where the cloud-side device is used to store the second file.
13. The method according to claim 12, characterized in that The number of bytes of the first file is greater than or equal to a third threshold, the first file is composed of a plurality of third files, and the number of bytes of the third files is less than the third threshold.
14. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory is used to store program instructions, and the processor is used to call the program instructions to execute the method according to any one of claims 1 to 13.
15. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed by a computer, the method according to any one of claims 1 to 13 is implemented.