Methods, devices, storage media, and electronic devices for storing small files
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHEJIANG DAHUA TECH CO LTD
- Filing Date
- 2023-01-11
- Publication Date
- 2026-06-30
Smart Images

Figure CN116303277B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computers, and more specifically, to a method, apparatus, storage medium, and electronic device for storing small files. Background Technology
[0002] Small files generally refer to single files ranging in size from a few kilobytes (KB) to a few megabytes (MB). File systems typically store files in blocks, with block sizes generally being several megabytes. When storing small files individually, each small file is usually of a fixed size. Storing data in a single small file may not fill the entire storage space for that small file, leading to wasted storage space. Furthermore, storing a large number of small files slows down file retrieval and reduces file read / write efficiency.
[0003] Currently, related technologies merge small files and store them in a large file, creating an index for the smaller files. This large file is also called a packaged file. However, these technologies either only delete the index information of the smaller files or require moving a large amount of data from the packaged file when deleting them, resulting in low efficiency for deleting small files.
[0004] There is currently no effective solution to the problem of low efficiency in deleting small files in related technologies. Summary of the Invention
[0005] This application provides a method, apparatus, storage medium, and electronic device for storing small files, in order to at least solve the problem of low efficiency in deleting small files in related technologies.
[0006] According to one embodiment of this application, a method for storing small files is provided, comprising: obtaining a first small file identifier, wherein the first small file identifier is used to identify a first small file to be deleted; deleting the first small file according to the first small file identifier and updating target index information, wherein the first small file is a small file packaged and stored in a first packaged file, the first packaged file includes a plurality of small files arranged in a preset order, the target index information includes the data length of the first small file, and a second small file is a small file packaged and stored in the first packaged file and located after the first small file in the preset order; moving the second small file according to the updated target index information, wherein the distance moved by the second small file is the same as the data length of the first small file.
[0007] According to another embodiment of this application, a storage device for small files is provided, comprising: an acquisition module, configured to acquire a first small file identifier, wherein the first small file identifier is used to identify a first small file to be deleted; a processing module, configured to delete the first small file according to the first small file identifier and update target index information, wherein the first small file is a small file packaged and stored in a first packaged file, the first packaged file includes a plurality of small files arranged in a preset order, the target index information includes the data length of the first small file, and the second small file is a small file packaged and stored in the first packaged file and located after the first small file in the preset order; and a moving module, configured to move the second small file according to the updated target index information, wherein the distance moved by the second small file is the same as the data length of the first small file.
[0008] Optionally, the device is further configured to: delete the first small file according to the first small file identifier, and determine first index information corresponding to the first small file, wherein the first index information includes the data length of the first small file and the position of the first small file in the first packaged file, and the target index information includes the first index information; search for second index information according to the first index information, wherein the second index information includes the data length of the second small file, the position of the second small file in the first packaged file, and the distance information that the second small file needs to be moved forward, and the target index information includes the second index information; delete the first index information, and update the second index information according to the data length of the first small file.
[0009] Optionally, the device is further configured to: determine a target forward movement distance based on the data length of the first small file, wherein the target forward movement distance is used to represent the distance that the second small file needs to be moved; and add the target forward movement distance to the second index information.
[0010] Optionally, the device is further configured to: acquire the updated target index information according to a preset period; and, if it is determined that the target index information indicates that the second small file needs to be moved forward, move the second small file forward, wherein the second index information corresponding to the second small file includes the distance that the second small file needs to be moved, and if the distance that the second small file needs to be moved is greater than 0, it is considered that the second small file needs to be moved.
[0011] Optionally, the device is further configured to: query the target index information to determine a list of packaged files in the target index information that have had small files deleted, wherein the list of packaged files includes the first packaged file that has had the first small file deleted; perform sorting processing on the first packaged file to determine the initial position of the second small file, wherein the initial position represents the sum of the data lengths of the small files located before the second small file before the deletion of the first small file; determine the current position of the second small file according to the target index information, wherein the current position represents the sum of the data lengths of the small files located before the second small file after the deletion of the first small file; and move the second small file if the initial position and the current position are different.
[0012] Optionally, the apparatus is further configured to: determine the difference between the initial position and the target forward movement distance as the current position when the target index information includes the target forward movement distance of the second small file, wherein the target forward movement distance is the same as the data length of the first small file; determine that the initial position and the current position are different when the target forward movement distance is not 0; and read the file data of the second small file from the initial position and write the file data to the target position when the initial position and the current position are different.
[0013] Optionally, the device is further configured to: update the target forward distance of the second small file in the target index information to 0, and update the position of the second small file in the target index information to the current position; truncate the first packaged file to the end of the last second small file to obtain a second packaged file, wherein the difference between the storage space of the second packaged file and the storage space of the first packaged file is the data length of the first small file.
[0014] According to yet another embodiment of this application, a computer-readable storage medium is also provided, wherein a computer program is stored therein, and the computer program is configured to perform the steps in any of the above method embodiments when it is run.
[0015] According to yet another embodiment of this application, an electronic device is also provided, including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to perform the steps in any of the above method embodiments.
[0016] This application's embodiments employ a method of obtaining a first small file identifier, deleting the first small file based on the identifier, updating the target index information, and then moving the second small file based on the updated target index information. This allows for dynamic deletion of small files, solving the problem of low efficiency in deleting small files in related technologies. After deleting small files, storage space in the packaged file is released, achieving the technical effect of improving the efficiency of deleting small files and increasing the utilization rate of the packaged file's storage space. Attached Figure Description
[0017] Figure 1 This is a hardware structure block diagram of a mobile terminal for a method of storing small files according to an embodiment of this application;
[0018] Figure 2 This is a flowchart of a method for storing small files according to an embodiment of this application;
[0019] Figure 3 This is a flowchart of another method for storing small files according to an embodiment of this application;
[0020] Figure 4 This is a flowchart of another method for storing small files according to an embodiment of this application;
[0021] Figure 5 This is a structural block diagram of a small file storage device according to an embodiment of this application. Detailed Implementation
[0022] The embodiments of this application will be described in detail below with reference to the accompanying drawings and examples.
[0023] It should be noted that the terms "first," "second," etc., in the specification, claims, and drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.
[0024] The methods and embodiments provided in this application can be executed on a mobile terminal, computer terminal, or similar computing device. Taking running on a mobile terminal as an example, Figure 1 This is a hardware structure block diagram of a mobile terminal for a small file storage method according to an embodiment of this application. For example... Figure 1 As shown, a mobile terminal may include one or more ( Figure 1 Only one is shown in the diagram. A processor 102 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 104 for storing data are also shown. The mobile terminal may further include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that... Figure 1The structure shown is for illustrative purposes only and does not limit the structure of the mobile terminal described above. For example, the mobile terminal may also include components that are more... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0025] The memory 104 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to the small file storage method in this embodiment. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, thus implementing the above-described method. The memory 104 may include high-speed random access memory and non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the mobile terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0026] The transmission device 106 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the mobile terminal's communication provider. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 may be a Radio Frequency (RF) module, used for wireless communication with the Internet.
[0027] This embodiment provides a method for storing small files. Figure 2 This is a flowchart of a small file storage method according to an embodiment of this application, such as... Figure 2 As shown, the process includes the following steps:
[0028] S202, Obtain the identifier of the first small file, whereby the identifier of the first small file is used to identify the first small file to be deleted;
[0029] S204, delete the first small file according to the first small file identifier and update the target index information, wherein the first small file is a small file packaged and stored in a first packaged file, the first packaged file includes multiple small files arranged in a preset order, the target index information includes the data length of the first small file, and the second small file is a small file packaged and stored in the first packaged file and located after the first small file in a preset order;
[0030] S206, move the second small file according to the updated target index information, wherein the distance moved by the second small file is the same as the data length of the first small file.
[0031] Optionally, in this embodiment, the first small file identifier may include, but is not limited to, manually labeled or intelligently generated; the first small file may include, but is not limited to, a small file to be deleted; and the content of the first small file may include, but is not limited to, images, text, audio, video, etc.
[0032] For example, the MD5 algorithm (Message-Digest Algorithm 5) can be used to generate the first small file identifier, thereby better distinguishing and deleting the first small file.
[0033] Optionally, in this embodiment, the first packaged file may include, but is not limited to, a large file used to merge and store multiple small files. The data in the first packaged file may include, but is not limited to, content in the same or different formats. For example, all the small files in the first packaged file may be stored in any of the formats such as images, audio, and text, or any combination of the above formats. The second small file may be a small file stored after the first small file in the first packaged file, or it may be a small file in the first packaged file other than the first small file. The second small file may refer only to a small file stored after the first small file in the first packaged file, or it may refer to multiple small files stored after the first small file in the first packaged file. Here, no specific limitation is made on the number of specific small files represented by the second small file.
[0034] Optionally, in this embodiment, the target index information may include, but is not limited to, the index information of all small files in the package file. The content of the index information may include, but is not limited to: the identifier of the small file, the identifier of the package file in which the small file is located, the position of the small file in the package file, the data length (size) of the small file, and the distance that the small file will be moved forward.
[0035] It should be noted that the preset order mentioned above may include, but is not limited to, the order of files from largest to smallest or smallest to largest, or the order in which they were stored in the first packaged file. No specific limitations are made on the setting of the preset order here. Taking the order in which small files were stored in the first packaged file as an example, the first packaged file, which includes multiple small files arranged in a preset order, can be understood as follows: multiple small files are arranged in the first packaged file according to the order in which they were stored. The small file that appears first in the first packaged file is the first small file stored in the first packaged file, and the small file that appears last in the first packaged file is the last small file stored in the first packaged file. The first small file is stored in the packaged file before the second small file.
[0036] This application embodiment employs a method of obtaining a first small file identifier, then deleting the first small file based on the first small file identifier, updating the target index information, and then moving the second small file based on the updated target index information. This allows for dynamic deletion of small files, solving the problem of low efficiency in deleting small files in related technologies. After deleting small files, storage space in the packaged file is released, achieving the technical effect of improving the efficiency of deleting small files and increasing the utilization rate of the packaged file's storage space.
[0037] In an exemplary embodiment, deleting a first small file based on a first small file identifier and updating target index information includes: deleting the first small file based on the first small file identifier and determining first index information corresponding to the first small file, wherein the first index information includes the data length of the first small file and the position of the first small file in the first packaged file, and the target index information includes the first index information; searching for second index information based on the first index information, wherein the second index information includes the data length of the second small file, the position of the second small file in the first packaged file, and the distance information that the second small file needs to be moved forward, and the target index information includes the second index information; deleting the first index information and updating the second index information based on the data length of the first small file.
[0038] Optionally, in this embodiment, the first index information may include, but is not limited to, the identifier of the first small file, the identifier of the first packaged file where the first small file is located, the length of the first small file (i.e., the size of the first small file), and the position of the first small file in the first packaged file. It should be noted that the position of the first small file in the first packaged file can be represented by the size of the first small file and the sum of the data lengths of the small files preceding the first small file. For example, the position of the first small file in the first packaged file can be represented as: (the sum of the data lengths of the small files preceding the first small file, the size of the first small file).
[0039] Optionally, in this embodiment, the second index information can be the index information of the second small file in the packaged file, in addition to the index information of the first small file. The content of the second index information may include, but is not limited to, the identifier of the second small file, the data length of the second small file, and the position of the second small file in the first packaged file.
[0040] For example, packaged file A contains three small files arranged in the order A1, A2, and A3, with A1 having a data length of 512kb, A2 having a data length of 512kb, and A3 having a data length of 1024kb. If A2 is the small file to be deleted, then A2 is the first small file mentioned above, and A3 is the second small file mentioned above. The position of A2 in the first packaged file can be represented as (512kb, 1024kb), which represents the start and end positions of the small file A2 stored in the packaged file. After deleting A2, the index information of A3 is updated according to the data length of A2.
[0041] In an exemplary embodiment, deleting the first index information and updating the second index information according to the data length of the first small file includes: determining the target forward movement distance according to the data length of the first small file, wherein the target forward movement distance is used to represent the distance that the second small file needs to be moved; and adding the target forward movement distance to the second index information.
[0042] Optionally, in this embodiment, the target forward movement distance is determined by the data length of the first small file. This can be understood as the data length of the deleted first small file and the distance that the second small file needs to move forward after deleting the first small file are corresponding. For example, packaged file A includes three small files arranged in the order A1, A2, and A3, and the data length of A1 is 512kb, the data length of A2 is 512kb, and the data length of A3 is 1024kb. If A2 is the small file to be deleted, then after deleting small file A2 and its index information, the target forward movement distance of small file A3 will be determined according to the data length of small file A2. Since the data length of small file A2 is 512kb, the target forward movement distance of small file A3 is 512kb.
[0043] It should be noted that adding the target forward movement distance to the second index information can be understood as follows: before the first small file to be deleted is determined, the second small file and its forward movement distance are also undetermined. After the first small file is deleted, the target forward movement distance of the second small file can be determined based on the data length of the first small file included in the index information of the first small file. Only then can the target forward movement distance of the second small file be specifically determined, and only then can the target forward movement distance of the second small file be updated in the second index information of the second small file.
[0044] In this embodiment, a first small file is deleted based on its identifier, and a first index corresponding to the first small file is determined. Then, a second index is found based on the first index, and the first index is deleted. The target forward movement distance is determined based on the data length of the first small file, and this target forward movement distance is added to the second index to update the second index. The target forward movement distance of the second small file after deletion can be determined based on the data length of the first small file recorded in its index information, thus making sufficient preparations for the subsequent movement of the second small file and improving the efficiency of moving the second small file after deleting the first.
[0045] In an exemplary embodiment, moving the second small file according to the updated target index information includes: obtaining the updated target index information at a preset period; and moving the second small file forward when it is determined that the target index information indicates that the second small file needs to be moved forward, wherein the second index information corresponding to the second small file includes the distance that the second small file needs to be moved, and the second small file is considered to need to be moved if the distance that the second small file needs to be moved is greater than 0.
[0046] Optionally, in this embodiment, the aforementioned preset period may include, but is not limited to, a time period that can be manually set by relevant technical personnel based on prior experience and can be changed at any time according to actual operational needs. The time period may include, but is not limited to, being set to 1 millisecond, 2 milliseconds, 1 second, etc.
[0047] It should be noted that the above-mentioned acquisition of updated target index information according to a preset period can be understood as acquiring updated target index information once every preset period. The updated target index information does not include the deleted first index information, but includes the updated second index information. The updated second index information records the distance that the second small file needs to be moved forward after the deletion of the first small file.
[0048] Optionally, in this embodiment, the above-mentioned "moving the second small file forward when the target index information indicates that the second small file needs to be moved forward" can be understood as moving the second small file according to the target moving distance recorded in the second index information when the distance that the second small file needs to be moved recorded in the second index information is greater than 0.
[0049] It should be noted that the above-mentioned moving the second small file forward may include, but is not limited to, moving multiple second small files that need to be moved one by one, or moving multiple second small files that need to be moved in batches.
[0050] This application's embodiments employ a method of acquiring updated target index information at a preset cycle, and then moving the second small file forward when the target index information indicates that the second small file needs to be moved. This allows the second small file to be moved directly to the corresponding position based on the distance recorded in the second index information. This method solves the technical problem of low efficiency in moving the second small file after deleting the first small file in a packaged file, achieving the technical effect of improving the moving efficiency of the second small file and saving moving time.
[0051] In an exemplary embodiment, moving the second small file according to the updated target index information includes: querying the target index information to determine a list of packaged files in the target index information that have had small files deleted, wherein the list of packaged files includes a first packaged file that has had a first small file deleted; performing sorting processing on the first packaged file to determine the initial position of the second small file, wherein the initial position represents the sum of the data lengths of the small files located before the second small file before the deletion of the first small file; determining the current position of the second small file according to the target index information, wherein the current position represents the sum of the data lengths of the small files located before the second small file after the deletion of the first small file; and moving the second small file if the initial position and the current position are different.
[0052] Optionally, in this embodiment, the above-mentioned packaged file list may include, but is not limited to, a list of packaged files in which small files in the packaged files are deleted within a preset period. The packaged file list may include, but is not limited to, one or more packaged files.
[0053] Optionally, in this embodiment, the initial position may include, but is not limited to, the position of the second small file in the first package file when the first small file has not been deleted. This position is determined by the sum of the data lengths of all small files before the second small file, or it may be determined by the sum of the data lengths of all small files before the second small file together with the data length of the second small file.
[0054] For example, a packaged file A contains three smaller files arranged in the order A1, A2, and A3, with A1 having a data length of 512kb, A2 having a data length of 512kb, and A3 having a data length of 1024kb. If A2 is the first smaller file and A3 is the second smaller file, the position of the second smaller file can be represented as (the sum of the data lengths of the preceding smaller files, and the data length of the second smaller file), i.e., (1024kb, 1024kb), or it can be directly represented as 1024kb.
[0055] It should be noted that the above sorting process for the first packaged file to determine the initial position of the second small file can be understood as sorting the small files in the first packaged file to determine the position of the second small file before deleting the first small file.
[0056] Optionally, in this embodiment, the current position refers to the sum of the data lengths of the small files located after the first small file is deleted and before the second small file. For example, in the above example, the current position of A3 can be represented as 512kb.
[0057] It should be noted that when the initial position and the current position are different, moving the second small file can be understood as follows: when the storage position of the second small file recorded in the target index information before and after the deletion of the first small file is inconsistent with that in the first package file, the second small file is moved from the initial position recorded in the target index information to the current position.
[0058] This application's embodiments query target index information to determine a list of packaged files containing deleted small files. Then, the first packaged file is sorted to determine the initial position of the second small file. The current position of the second small file is then determined based on the target index information. If the initial and current positions differ, the second small file is moved. Whether the second small file needs to be moved can be determined by whether its initial and current positions in the target index information before and after the deletion of the first small file are consistent. If they are consistent, the second small file does not need to be moved; otherwise, it needs to be moved from its initial position to its current position. By updating the index information of the second small file before starting a thread to move the second small file, the technical effects of improving the moving efficiency of the second small file, saving operation time, and improving user experience are achieved.
[0059] In an exemplary embodiment, determining the current position of the second small file based on the target index information includes: if the target index information includes the target forward movement distance of the second small file, determining the difference between the initial position and the target forward movement distance as the current position, wherein the target forward movement distance is the same as the data length of the first small file; if the initial position and the current position are different, moving the second small file includes: if the target forward movement distance is not 0, determining that the initial position and the current position are different; if the initial position and the current position are different, reading the file data of the second small file from the initial position and writing the file data to the target position.
[0060] Optionally, in this embodiment, the target location may include, but is not limited to, the location where the second small file should be moved from the initial location after the first small file is deleted.
[0061] For example, a packaged file A contains three smaller files arranged in the order A1, A2, and A3, with A1 and A2 each having a data length of 512kb and 1024kb respectively. If A2 is the first smaller file and A3 is the second, and A3's initial position is 1024kb, after deleting A2, A3's target forward distance is 512kb. The difference between A3's initial position (1024kb) and its target forward distance (512kb) is then determined as its current position. Since A3's initial position (1024kb) and current position (512kb) are different, A3 is moved to the target position (512kb - 1536kb), and 1024kb of file data from A3 is read from its initial position (1024kb) and written to the target position.
[0062] In this embodiment, when the target index information includes the target forward movement distance of the second small file, the difference between the initial position and the target forward movement distance is determined as the current position. Then, if the initial position and the current position are different, the second small file is moved. This includes: if the target forward movement distance is not zero, determining that the initial position and the current position are different; if the initial position and the current position are different, reading the file data of the second small file from the initial position and writing the file data to the target position. The system determines whether the second small file needs to be moved based on whether the initial position and the current position of the second small file recorded in the target index information before and after the deletion of the first small file are consistent. If the initial position and the current position are consistent, the second small file does not need to be moved; if they are inconsistent, the second small file needs to be moved. By first updating the index information of the second small file and then starting a thread to move the second small file to be moved and its data, the technical effect of improving the moving efficiency of the second small file, saving operation time, and improving the user experience is achieved.
[0063] In an exemplary embodiment, after moving the second small file according to the updated target index information, the method further includes: updating the target forward movement distance of the second small file in the target index information to 0, and updating the position of the second small file in the target index information to the current position; truncating the first packaged file to the end of the last second small file to obtain a second packaged file, wherein the difference between the storage space of the second packaged file and the storage space of the first packaged file is the data length of the first small file.
[0064] Optionally, in this embodiment, the second packaged file may include, but is not limited to, a packaged file obtained by deleting the first small file from the first packaged file and moving the second small file and its data to the target location.
[0065] By adopting the method of updating the target forward distance of the second small file in the target index information to 0, updating the position of the second small file in the target index information to the current position, and then truncating the first packaged file to the end of the last second small file to obtain the second packaged file, the technical problem of the memory of the first small file not being released after deleting the first small file of the first packaged file is solved. By moving the second small file after deleting the first small file and truncating the first packaged file to the end of the last second small file, the memory of the deleted first small file is released, thereby achieving the technical effect of improving the storage space utilization efficiency of the packaged file.
[0066] Obviously, the embodiments described above are only some of the embodiments of this application, and not all of the embodiments.
[0067] The present application will be described in detail below with reference to specific embodiments:
[0068] This application optimizes a common method for merging and storing small files. In this common method, index information is created for small files, including the small file's identifier, the identifier of the larger file containing the small file, the small file's position within the larger file, and the small file's length. This index information is stored in an indexing system, which can be, but is not limited to, a database system. This proposal adds a new index: the distance that subsequent small files will be shifted forward after a small file is deleted.
[0069] The data structure of the indexing system is shown in the table below:
[0070]
[0071] This application deletes a small file, which consists of two steps: 1. Update the index information; 2. Start a thread to move the small file at regular intervals.
[0072] The detailed process is as follows:
[0073] I. Update index information:
[0074] Figure 3 This is a flowchart of another method for storing small files according to an embodiment of this application, such as... Figure 3 As shown, the specific steps for updating index information are as follows:
[0075] S302, Begin;
[0076] S304, Delete the small file (corresponding to the first small file identifier mentioned above) by specifying the small file identifier;
[0077] S306, Delete the index information of the small file from the indexing system;
[0078] S308, Search the index system for all small files that are in the same large file as the deleted small file and whose position in the large file is greater than that of the deleted small file;
[0079] S310, add the forward shift distance of the found small file to the length of the deleted small file;
[0080] S312, End.
[0081] 2. Enable thread-based timed movement of small files:
[0082] Figure 4 This is a flowchart of another method for storing small files according to an embodiment of this application, such as... Figure 4 As shown, the specific steps to start a thread to periodically move small files are as follows:
[0083] S402, start a thread to periodically query the index information of small files that need to be moved forward from the index system;
[0084] S404. Based on the "identifier of the large file where the small file is located" in the index information of the retrieved small files, determine the list of large files that need to be processed.
[0085] S406: For each large file, process its smaller files in ascending order of their position within the large file.
[0086] S408, the new position of the small file is obtained by subtracting the "small file's forward shift distance" from the "small file's position in the large file".
[0087] S410, if the old and new positions of a small file are different, move the small file: read data from the old position and write it to the new position;
[0088] S412, after moving the small file, update the "position of the small file in the large file" in the indexing system and set the "moving distance of the small file" to 0;
[0089] S414: After all the smaller files in a large file have been processed, truncate the large file to the end of the last smaller file.
[0090] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods of the various embodiments of this application.
[0091] This embodiment also provides a small file storage device for implementing the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can refer to a combination of software and / or hardware that performs a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0092] Figure 5 This is a structural block diagram of a small file storage device according to an embodiment of this application, such as... Figure 5 As shown, the device includes:
[0093] The acquisition module 502 is used to acquire the identifier of the first small file, wherein the identifier of the first small file is used to identify the first small file to be deleted;
[0094] The processing module 504 is used to delete the first small file according to the first small file identifier and update the target index information. The first small file is a small file that is packaged and stored in a first packaged file. The first packaged file includes multiple small files arranged in a preset order. The target index information includes the data length of the first small file. The second small file is a small file that is packaged and stored in the first packaged file and is located after the first small file in a preset order.
[0095] The moving module 506 is used to move the second small file according to the updated target index information, wherein the distance moved by the second small file is the same as the data length of the first small file.
[0096] In an exemplary embodiment, the above-described apparatus is further configured to: delete a first small file based on a first small file identifier, and determine first index information corresponding to the first small file, wherein the first index information includes the data length of the first small file and the position of the first small file in the first packaged file, and the target index information includes the first index information; search for second index information based on the first index information, wherein the second index information includes the data length of the second small file, the position of the second small file in the first packaged file, and the distance information that the second small file needs to be moved forward, and the target index information includes the second index information; delete the first index information, and update the second index information based on the data length of the first small file.
[0097] In an exemplary embodiment, the above-described apparatus is further configured to: determine a target forward movement distance based on the data length of the first small file, wherein the target forward movement distance is used to represent the distance that the second small file needs to be moved; and add the target forward movement distance to the second index information.
[0098] In an exemplary embodiment, the above-described apparatus is further configured to: acquire updated target index information according to a preset period; and, if it is determined that the target index information indicates that the second small file needs to be moved forward, move the second small file forward, wherein the second index information corresponding to the second small file includes the distance that the second small file needs to be moved, and if the distance that the second small file needs to be moved is greater than 0, it is considered that the second small file needs to be moved.
[0099] In an exemplary embodiment, the above-described apparatus is further configured to: query target index information to determine a list of packaged files in the target index information that have had small files deleted, wherein the list of packaged files includes a first packaged file that has had a first small file deleted; perform sorting processing on the first packaged file to determine the initial position of the second small file, wherein the initial position represents the sum of the data lengths of the small files located before the second small file before the deletion of the first small file; determine the current position of the second small file according to the target index information, wherein the current position represents the sum of the data lengths of the small files located before the second small file after the deletion of the first small file; and move the second small file if the initial position and the current position are different.
[0100] In an exemplary embodiment, the above-described apparatus is further configured to: determine the current position of the second small file based on target index information, including: if the target index information includes a target forward movement distance of the second small file, determining the difference between the initial position and the target forward movement distance as the current position, wherein the target forward movement distance is the same as the data length of the first small file; if the initial position and the current position are different, moving the second small file, including: if the target forward movement distance is not 0, determining that the initial position and the current position are different; if the initial position and the current position are different, reading the file data of the second small file from the initial position and writing the file data to the target position.
[0101] In an exemplary embodiment, the above-described apparatus is further configured to: update the target forward distance of the second small file in the target index information to 0, and update the position of the second small file in the target index information to the current position; truncate the first packaged file to the end of the last second small file to obtain a second packaged file, wherein the difference between the storage space of the second packaged file and the storage space of the first packaged file is the data length of the first small file.
[0102] Embodiments of this application also provide a computer-readable storage medium storing a computer program, wherein the computer program is configured to execute the steps in any of the above method embodiments when run.
[0103] In one exemplary embodiment, the aforementioned computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard disk, magnetic disk, or optical disk.
[0104] Embodiments of this application also provide an electronic device including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to perform the steps in any of the above method embodiments.
[0105] In one exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor and the input / output device is connected to the processor.
[0106] Specific examples in this embodiment can be found in the examples described in the above embodiments and exemplary implementations, and will not be repeated here.
[0107] Obviously, those skilled in the art should understand that the modules or steps of this application described above can be implemented using general-purpose computing devices. They can be centralized on a single computing device or distributed across a network of multiple computing devices. They can be implemented using computer-executable program code, and thus can be stored in a storage device for execution by a computing device. In some cases, the steps shown or described can be performed in a different order than those presented here, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, this application is not limited to any particular combination of hardware and software.
[0108] The above are merely preferred embodiments of this application and are not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the principles of this application should be included within the protection scope of this application.
Claims
1. A small file storage method characterized by comprising: include: Obtain the identifier of the first small file, wherein the identifier of the first small file is used to identify the first small file to be deleted; The first small file is deleted according to the first small file identifier, and the first index information corresponding to the first small file is determined. The second index information is found according to the first index information, the first index information is deleted, and the second index information is updated according to the data length of the first small file. The first small file is a small file that is packaged and stored in a first packaged file. The first index information includes the data length of the first small file and the position of the first small file in the first packaged file. The target index information includes the first index information and the second index information. The second index information includes the data length of the second small file, the position of the second small file in the first packaged file, and the distance information that the second small file needs to be moved forward. The second small file is stored in the first packaged file and is located after the first small file in a preset order. The multiple small files are arranged in the first packaged file according to the order in which they were stored. The first small file is stored in the first packaged file before the second small file. The target index information is queried to determine the list of packaged files in the target index information where small files have been deleted. The first packaged file is sorted to determine the initial position of the second small file. The current position of the second small file is determined according to the target index information. If the initial position and the current position are different, the second small file is moved. The packaged file list includes the first packaged file where the first small file has been deleted. The initial position represents the sum of the data lengths of the small files located before the second small file before the first small file was deleted. The current position represents the sum of the data lengths of the small files located before the second small file after the first small file was deleted. The second small file is moved according to the target forward movement distance recorded in the second index information, wherein the target forward movement distance is determined based on the data length of the first small file after the first small file is deleted.
2. The method of claim 1, wherein, Moving the second small file according to the updated target index information includes: The updated target index information is obtained according to a preset period; If the target index information indicates that the second small file needs to be moved forward, the second small file is moved forward. The second index information corresponding to the second small file includes the distance that the second small file needs to be moved. If the distance that the second small file needs to be moved is greater than 0, the second small file is considered to need to be moved.
3. The method according to claim 1, characterized in that, Determining the current position of the second small file based on the target index information includes: when the target index information includes the target forward movement distance of the second small file, determining the difference between the initial position and the target forward movement distance as the current position, wherein the target forward movement distance is the same as the data length of the first small file; Moving the second small file when the initial position and the current position are different includes: determining that the initial position and the current position are different when the target forward movement distance is not 0; reading the file data of the second small file from the initial position and writing the file data to the target position when the initial position and the current position are different.
4. The method of claim 3, wherein, After moving the second small file according to the updated target index information, the method further includes: Update the target forward movement distance of the second small file in the target index information to 0, and update the position of the second small file in the target index information to the current position; The first packaged file is truncated to the end of the last second small file to obtain the second packaged file, wherein the difference between the storage space of the second packaged file and the storage space of the first packaged file is the data length of the first small file.
5. A storage device for small files, characterized by include: The acquisition module is used to acquire the identifier of the first small file, wherein the identifier of the first small file is used to identify the first small file to be deleted; The processing module is configured to delete the first small file based on the first small file identifier, determine the first index information corresponding to the first small file, search for the second index information based on the first index information, delete the first index information, and update the second index information based on the data length of the first small file. The first small file is a small file packaged and stored in a first packaged file. The first index information includes the data length of the first small file and its position in the first packaged file. The target index information includes the first index information and the second index information. The second index information includes the data length of the second small file, its position in the first packaged file, and the distance the second small file needs to be moved forward. The second small file is stored in the first packaged file and is located after the first small file in a preset order. Multiple small files are arranged in the first packaged file according to the order in which they were stored, with the first small file stored before the second small file. The device is further configured to: query the target index information, determine a list of packaged files in the target index information that have had small files deleted, perform sorting processing on the first packaged file, determine the initial position of the second small file, determine the current position of the second small file according to the target index information, and move the second small file if the initial position and the current position are different, wherein the list of packaged files includes the first packaged file that has had the first small file deleted, the initial position represents the sum of the data lengths of the small files located before the second small file before the first small file was deleted, and the current position represents the sum of the data lengths of the small files located before the second small file after the first small file was deleted; The device is further configured to: move the second small file according to the target forward movement distance recorded in the second index information, wherein the target forward movement distance is determined based on the data length of the first small file after the first small file is deleted.
6. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements the steps of the method according to any one of claims 1 to 4.
7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 4.