A method, apparatus, device and storage medium for modifying a zip file
By determining the original region of the ZIP file and generating the target region, and using a file appending mechanism to add modified data to the end of the ZIP file, the problems of easy corruption and low efficiency in ZIP file modification are solved, achieving lossless and efficient ZIP file modification.
Patent Information
- Application Number
- CN202311152631.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-07
- Publication Date
- 2025-12-19
- Estimated Expiration
- 2043-09-07
AI Technical Summary
Existing techniques are prone to causing file corruption when modifying ZIP files, and are inefficient for modifying large files.
The target region is generated by determining the original region of the initial Zip file, including the original data region, the central record region, and the tail region. The target region is then added to the tail of the original region using a file appending mechanism to generate the target Zip file.
It ensures lossless modification of ZIP files while improving modification efficiency, avoiding file corruption, and speeding up the modification process for large files.
Smart Images

Figure CN117194343B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present application relate to the field of information security and computer application technology, in particular to the field of file compression technology, and specifically to a Zip file modification method, device, equipment and storage medium. BACKGROUND
[0002] As a popular compressed file format, Zip files provide a convenient way of file storage and sharing by using compression algorithms, file indexing, directory structures and other technologies, and are widely used in file transfer, backup and archiving fields.
[0003] In the prior art, modifying a Zip file, such as adding a file, will compress the new file into the data area, then add the corresponding entry in the central recording area, and adjust the offset of each area; deleting and replacing files will also change the Zip areas. However, modifying each area of the Zip file can easily cause file damage; and if the Zip file is very large, modifying each area of the Zip file will consume a lot of time. SUMMARY
[0004] The present application provides a Zip file modification method, device, equipment and storage medium to ensure lossless modification of Zip files while improving the efficiency of Zip file modification.
[0005] According to an aspect of the present application, a Zip file modification method is provided, which comprises:
[0006] determining an original area of an initial Zip file; wherein the original area comprises an original data area, an original central recording area and an original tail area;
[0007] generating a target area for modifying the initial Zip file according to the original area;
[0008] generating a target Zip file according to the original area and the target area.
[0009] According to another aspect of the present application, a Zip file modification device is provided, which comprises:
[0010] an original area determination module for determining an original area of an initial Zip file; wherein the original area comprises an original data area, an original central recording area and an original tail area;
[0011] a target area determination module for generating a target area for modifying the initial Zip file according to the original area;
[0012] a file generation module for generating a target Zip file according to the original area and the target area.
[0013] According to another aspect of the present application, an electronic device is provided, the electronic device comprising:
[0014] one or more processors;
[0015] a memory for storing one or more programs;
[0016] When the one or more programs are executed by the one or more processors, the one or more processors implement any one of the Zip file modification methods provided by the embodiments of the present application.
[0017] According to another aspect of the present application, a computer readable storage medium is provided, having stored thereon a computer program, which when executed by a processor implements any one of the Zip file modification methods provided by the embodiments of the present application.
[0018] The present application determines an original area of an initial Zip file, wherein the original area comprises an original data area, an original central recording area and an original tail area; generates a target area for modifying the initial Zip file according to the original area; and generates a target Zip file according to the original area and the target area. The above technical solution sets the target area for modifying the Zip file, ensures lossless modification of the Zip file, and improves the modification efficiency of the Zip file.
[0019] It should be understood that the content described in this section is not intended to identify key or important features of the embodiments of the application, nor is it used to limit the scope of the application. Other features of the application will become apparent through the following description. BRIEF DESCRIPTION OF DRAWINGS
[0020] Figure 1 is a flowchart of a Zip file modification method according to Embodiment One of the present application;
[0021] Figure 2 is a flowchart of a Zip file modification method according to Embodiment Two of the present application;
[0022] Figure 3 is a structural schematic diagram of a Zip file modification device according to Embodiment Three of the present application;
[0023] Figure 4 is a structural schematic diagram of an electronic device implementing the Zip file modification method of the present application. DETAILED DESCRIPTION
[0024] In the following, the technical solutions in the embodiments of the present application will be described clearly and completely with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all the other embodiments obtained by those skilled in the art without creative work should fall into the protection scope of the present application.
[0025] It should be noted that the terms "first", "second" and the like in the description and claims of the present application and the above drawings are used to distinguish similar objects, and do not necessarily indicate a specific order or sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present application described herein can be implemented in other than the order illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device that includes a list of steps or units need not be limited to those steps or units clearly listed, but can include other steps or units not clearly listed or inherent to such processes, methods, products or devices.
[0026] In addition, it should also be noted that in the technical solutions of the present application, the collection, storage, use, processing, transmission, provision and disclosure of the related data such as regional information and original region, etc. comply with the relevant legal regulations and do not violate public order and good customs.
[0027] Embodiment one
[0028] Figure 1 It is a flowchart of a Zip file modification method according to the first embodiment of the present application. The present embodiment can be applied to the case of modifying a Zip file, and can be executed by a Zip file modification device. The Zip file modification device can be realized in the form of hardware and / or software, and can be configured in a computer device, such as a server. As shown in the figure, the method comprises: Figure 1
[0029] S110, determining the original region of the initial Zip file; wherein the original region includes an original data area, an original central recording area and an original tail area.
[0030] The Zip file is composed of a series of files and directories, and contains original files compressed and related metadata information. The initial Zip file refers to a Zip file that has not been modified. The original area refers to a constituent area of the initial Zip file. The original data area is one of the constituent areas of the initial Zip file, and is used to store metadata information of the Zip file, including at least one of a file format version number, creation and modification time of the file, size of the file, and CRC checksum. The original central recording area is one of the constituent areas of the initial Zip file, and is used to record information of all compressed files, such as file name and size. The original tail area is one of the constituent areas of the initial Zip file, and is used to locate and read the central recording area, and contains attributes such as position offset of the central recording area.
[0031] Specifically, the initial Zip file is opened, and the initial Zip file is parsed to determine the original data area, the original central recording area, and the original tail area in the Zip file.
[0032] S120, generating a target area for modifying the initial Zip file according to the original area.
[0033] The target area refers to an area corresponding to the original area for modifying the Zip file, which includes a data area, a central recording area, and a tail area corresponding to each area in the original area, and is used to store and manage modification data of the initial Zip file.
[0034] Specifically, the original area of the initial Zip file is determined, and a target area for modifying the Zip file corresponding to the original area is generated according to related information in the original area.
[0035] S130, generating a target Zip file according to the original area and the target area.
[0036] The target Zip file refers to a Zip file composed of the original area and the target area.
[0037] Optionally, the target area is appended to the tail of the original area based on a file appending mechanism to generate the target Zip file.
[0038] The file appending mechanism is a mechanism for adding content at the end of an existing file, which is used to append new data to an existing file without damaging the content of the original file.
[0039] Specifically, the content is read from the initial Zip file based on a preset reading mode; the pointer of the initial Zip file is positioned to the end of the file; the target area is written to the tail of the initial Zip file using a write operation; after the data writing is completed, the initial Zip file is closed; and the initial Zip file with successful writing is taken as the target Zip file.
[0040] It should be noted that the preset read mode is artificially set according to actual conditions or experience values, and can be at least one of the read-only mode and the append mode, and the embodiments of the present application do not make specific limitations.
[0041] It can be understood that the file append mechanism can ensure that the target area is added to the correct position of the initial Zip and ensure the integrity of file processing and the release of resources.
[0042] The embodiments of the present application determine the original area of the initial Zip file; wherein the original area includes an original data area, an original central recording area and an original tail area; generate a target area for modifying the initial Zip file according to the original area; and generate a target Zip file according to the original area and the target area. The above technical solution sets the target area for modifying the Zip file, ensures lossless modification of the Zip file, and improves the modification efficiency of the Zip file.
[0043] Embodiment two
[0044] Figure 2 is a flowchart of a Zip file modification method according to the second embodiment of the present application. Based on the technical solutions of the above embodiments, the "generating a target area for modifying the initial Zip file according to the original area" is refined to "determining the area information of the original area; wherein the area information includes the current data of the original central recording area, the data format of the original data area and the file size of the initial Zip file; and generating a target area for modifying the Zip file according to the area information". It should be noted that the parts not described in detail in the embodiments of the present application can be referred to the related descriptions of other embodiments. For example, Figure 2 as shown, the method comprises:
[0045] S210, determining the original area of the initial Zip file; wherein the original area includes an original data area, an original central recording area and an original tail area.
[0046] S220, determining the area information of the original area; wherein the area information includes the current data of the original central recording area, the data format of the original data area and the file size of the initial Zip file.
[0047] The area information refers to the relevant information of the initial Zip file stored in the original area, including at least one of the file size, the data type, etc. The current data of the original central recording area refers to at least one of the information of all compressed files, such as the file name, the size, etc. The data format of the original data area refers to the format of the data stored in the current data area. The file size of the initial Zip file refers to the storage space size occupied by the compressed ZIP file.
[0048] Specifically, information is read from the original area of the initial Zip file in a preset reading mode, and the current data of the original central recording area, the data format of the original data area, and the file size of the initial Zip file are recorded.
[0049] It should be noted that the preset reading mode is artificially set according to actual conditions or experience values, and the reading operation of the Zip file can be performed through at least one of a file API or a Zip library, and the present application embodiment does not make specific limitations.
[0050] S230, generating a target area for modifying the Zip file according to the area information.
[0051] Optionally, an additional data area, a new central recording area, and a new tail area are generated according to the area information; and the target area for modifying the Zip file is determined according to the additional data area, the new central recording area, and the new tail area.
[0052] The additional data area refers to an area for storing modified data of the Zip file. The new central recording area refers to an area for recording information of the modified file. The new tail area is used to record the data offset of the new central recording area.
[0053] Specifically, the additional data area, the new central recording area, and the new tail area are generated in sequence according to the data format of the original data area, the current data of the original central recording area, and the file size of the initial Zip file, and the additional data area, the new central recording area, and the new tail area form the target area for modifying the Zip file.
[0054] Further, the additional data area is generated according to the data format of the original data area; a blank central recording area and a blank tail area are generated; the current data of the original central recording area is copied to the blank central recording area to generate the new central recording area; and the file size of the initial Zip file is saved to the blank tail area to generate the new tail area.
[0055] The blank central recording area refers to a temporary central recording area that does not store any data information. The blank tail area refers to a temporary tail area that does not store any data information.
[0056] Specifically, the additional data area with consistent data format is generated according to the data format of the original data area; the blank central recording area is generated, and the current data of the original central recording area is copied to the blank central recording area; the blank central recording area storing the current data of the original central recording area is used as the new central recording area; the blank tail area is generated, and the file size of the initial Zip file is saved to the blank tail area; and the blank tail area storing the file size of the initial Zip file is used as the new tail area.
[0057] It can be understood that copying the information of the initial Zip file to the target area can realize the modification of the Zip file in the target area without affecting the initial Zip file; and the new tail area records the file size of the initial Zip file, which is helpful for file restoration.
[0058] S240, generating a target Zip file according to the original area and the target area.
[0059] Optionally, the target Zip file is checked based on a preset file checking method.
[0060] Specifically, after the target Zip file is generated, the file content, file size and function of the target Zip file are checked based on a preset file checking method.
[0061] It should be noted that the preset file checking method includes at least one of data and checking, file size comparison, file content comparison and function test, and the present application embodiment does not make specific limitation thereto.
[0062] Illustratively, the original area and the target area of the target Zip file are determined, and by comparing with the original area of the initial Zip file, it is determined whether the content of the original area and the target area of the target Zip file is correct; or, the target Zip file is tested for specific functions to verify whether the target Zip file can be used to modify the Zip file.
[0063] Further, if the checking passes, it is determined that the target Zip file is normal; if the checking does not pass, the target Zip file is detected for abnormality.
[0064] The abnormality detection is used to detect abnormal situations in the target Zip file and the causes of the abnormal situations; the abnormal situations can be at least one of being unable to add or delete files in the target area.
[0065] It can be understood that further checking the target Zip file can effectively ensure the normal use of the target Zip file, and avoid problems such as damage of the file to be modified subsequently due to abnormality of the target Zip file.
[0066] The embodiment of the present application determines the original area of the initial Zip file, wherein the original area includes an original data area, an original central recording area and an original tail area; determines area information of the original area; wherein the area information includes current data of the original central recording area, a data format of the original data area and a file size of the initial Zip file; generates a target area for modifying the Zip file according to the area information; and generates a target Zip file according to the original area and the target area. The above technical solution can realize Zip file modification in the target area without affecting the initial Zip file, and helps to improve the modification efficiency of the Zip file.
[0067] Embodiment three
[0068] Figure 3 Fig. 1 is a structure schematic diagram of a Zip file modification device according to an embodiment of the present application, which can be applied to the case of modifying a Zip file. The Zip file modification device can be realized in the form of hardware and / or software, and can be configured in a computer device, such as a server. As shown in Fig. 1, the device includes: Figure 3
[0069] An original area determination module 310 is configured to determine the original area of the initial Zip file, wherein the original area includes an original data area, an original central recording area and an original tail area;
[0070] A target area determination module 320 is configured to generate a target area for modifying the initial Zip file according to the original area;
[0071] A file generation module 330 is configured to generate a target Zip file according to the original area and the target area.
[0072] The embodiment of the present application determines the original area of the initial Zip file, wherein the original area includes an original data area, an original central recording area and an original tail area; generates a target area for modifying the initial Zip file according to the original area; and generates a target Zip file according to the original area and the target area. The above technical solution sets the target area for modifying the Zip file, ensures lossless modification of the Zip file, and improves the modification efficiency of the Zip file.
[0073] Optionally, the target area determination module 320 includes:
[0074] An information determination unit is configured to determine area information of the original area, wherein the area information includes current data of the original central recording area, a data format of the original data area and a file size of the initial Zip file;
[0075] The region determining unit is configured to generate a target region for modifying the Zip file according to the region information.
[0076] Optionally, the region determining unit comprises:
[0077] The region generating subunit is configured to generate the additional data region, the new central recording region and the new tail region according to the region information.
[0078] The region determining subunit is configured to determine the target region for modifying the Zip file according to the additional data region, the new central recording region and the new tail region.
[0079] Optionally, the region generating subunit is specifically configured to:
[0080] generate the additional data region according to the data format of the original data region;
[0081] generate the blank central recording region and the blank tail region;
[0082] copy current data of the original central recording region to the blank central recording region to generate the new central recording region;
[0083] save a file size of the initial Zip file to the blank tail region to generate the new tail region.
[0084] Optionally, the file generating module 330 is specifically configured to:
[0085] append the target region to a tail of the original region based on a file appending mechanism to generate the target Zip file.
[0086] Optionally, the Zip file modifying apparatus further comprises:
[0087] The file verifying module is configured to verify the target Zip file based on a preset file verifying method.
[0088] Optionally, the file verifying module is further configured to:
[0089] if the verification passes, determine that the target Zip file is normal;
[0090] if the verification fails, perform an abnormality detection on the target Zip file.
[0091] The Zip file modifying apparatus provided in the embodiments of the present application can execute the Zip file modifying method provided in any of the embodiments of the present application, and has the corresponding function modules and beneficial effects of executing the Zip file modifying method.
[0092] Embodiment four
[0093] Figure 4This is a schematic diagram of the structure of an electronic device 410 implementing the method for modifying ZIP files according to embodiments of this application. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present application described and / or claimed herein.
[0094] like Figure 4 As shown, the electronic device 410 includes at least one processor 411 and a memory, such as a read-only memory (ROM) 412 or a random access memory (RAM) 413, communicatively connected to the at least one processor 411. The memory stores computer programs executable by the at least one processor. The processor 411 can perform various appropriate actions and processes based on the computer program stored in the ROM 412 or loaded from storage unit 418 into the RAM 413. The RAM 413 may also store various programs and data required for the operation of the electronic device 410. The processor 411, ROM 412, and RAM 413 are interconnected via a bus 414. An input / output (I / O) interface 415 is also connected to the bus 414.
[0095] Multiple components in electronic device 410 are connected to I / O interface 415, including: input unit 416, such as keyboard, mouse, etc.; output unit 417, such as various types of displays, speakers, etc.; storage unit 418, such as disk, optical disk, etc.; and communication unit 419, such as network card, modem, wireless transceiver, etc. Communication unit 419 allows electronic device 410 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0096] Processor 411 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 411 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 411 performs the various methods and processes described above, such as the method of modifying a ZIP file.
[0097] In some embodiments, the method of modifying a Zip file can be implemented as a computer program tangibly embodied in a computer readable storage medium, e.g., storage unit 418. In some embodiments, some or all of the computer program can be loaded and / or installed onto electronic device 410 via, e.g., ROM 412 and / or communication unit 419. When the computer program is loaded onto RAM 413 and executed by processor 411, one or more of the steps of the method of modifying a Zip file described above can be performed. Alternatively, in other embodiments, processor 411 can be configured to the method of modifying a Zip file by any other suitable means, e.g., with firmware.
[0098] Various implementations of the systems and techniques described above can be realized in digital electronic circuitry, integrated circuitry, a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on a chip (SOC), a programmable logic device (PLD), a computer hardware, firmware, software, and / or combinations thereof. These various implementations can include implementation in one or more computer programs that are executable and / or interpretable on a programmable system including at least one programmable processor, which can be special or general purpose, coupled to receive data and instructions from, and to transmit data and instructions to, a storage system, at least one input device, and at least one output device.
[0099] Computer programs used to implement the methods of the present application can be written in any combination of one or more programming languages. These computer programs can be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the computer program, when executed by the processor of the machine, implements the functions / acts specified in the flowcharts and / or block diagrams. The computer program can be executed entirely on a machine, partially on a machine, partially on a machine and partially on a remote machine or entirely on a remote machine or server.
[0100] In the context of this application, a computer readable storage medium can be a tangible medium that can contain or store computer programs for use by or in connection with an instruction execution system, apparatus, or device. Computer readable storage media can include, but are not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. Alternatively, a computer readable storage medium can be a machine readable signal medium. More specific examples of a machine readable storage medium will include one or more lines of a program of instructions in a transitory signal form, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0101] To provide for interaction with a user, the systems and techniques described here can be implemented on an electronic device having a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the electronic device. Other kinds of devices can be used to provide for interaction with a user as well; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form, including acoustic, speech, or tactile input.
[0102] The systems and techniques described here can be implemented in a computing system that includes a back end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front end component (e.g., a user computer having a graphical user interface or a Web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back end, middleware, or front end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0103] The computing system can include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system, to solve the defects of large management difficulty and weak business scalability in traditional physical host and VPS service.
[0104] It should be understood that the various forms of flow shown above can be reordered, added to, or have steps deleted. For example, the steps described in this application can be performed in parallel, in series, or in a different order, as long as the desired results of the technical solutions of this application can be achieved, and this application does not limit herein.
[0105] The above detailed description does not constitute a limitation on the scope of protection of the present application. Those skilled in the art should understand that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modifications, equivalent replacements and improvements made within the spirit and principles of the present application shall be included in the scope of protection of the present application.
Claims
1. A method of modifying a Zip file, characterized by, The method comprises the following steps: determining an original area of an initial Zip file; wherein the original area comprises an original data area, an original central record area and an original tail area; determining area information of the original area; wherein the area information comprises current data of the original central record area, a data format of the original data area and a file size of the initial Zip file; generating an additional data area, a new central record area and a new tail area according to the area information; determining a target area for modifying the Zip file according to the additional data area, the new central record area and the new tail area; appending the target area to a tail of the original area based on a file appending mechanism to generate a target Zip file.
2. The method of claim 1, wherein, The generating of the additional data area, the new central record area and the new tail area according to the area information comprises: generating the additional data area according to the data format of the original data area; generating a blank central record area and a blank tail area; copying the current data of the original central record area to the blank central record area to generate the new central record area; saving the file size of the initial Zip file to the blank tail area to generate the new tail area.
3. The method of claim 1, wherein, After generating the target Zip file, the method further comprises: checking the target Zip file based on a preset file checking method.
4. The method of claim 3, wherein, The method further comprises: if the checking passes, determining that the target Zip file is normal; if the checking fails, performing an abnormality detection on the target Zip file.
5. An apparatus for modifying a Zip file, characterized by The method comprises: an original area determining module configured to determine an original area of an initial Zip file; wherein the original area comprises an original data area, an original central record area and an original tail area; a target area determining module configured to generate a target area for modifying the initial Zip file according to the original area; a file generating module configured to generate a target Zip file according to the original area and the target area. The target area determining module is specifically configured to: determine area information of the original area; wherein the area information comprises current data of the original central record area, a data format of the original data area and a file size of the initial Zip file; generate an additional data area, a new central record area and a new tail area according to the area information; determine a target area for modifying the Zip file according to the additional data area, the new central record area and the new tail area. The file generating module is specifically configured to: append the target area to a tail of the original area based on a file appending mechanism to generate the target Zip file.
6. An electronic device, comprising: The method comprises: one or more processors; a memory configured to store one or more programs; when the one or more programs are executed by the one or more processors, the one or more processors implement the method for modifying a Zip file according to any one of claims 1-4.
7. A computer-readable storage medium having stored thereon a computer program, characterized in that, The program is executed by the processor to implement the method for modifying a Zip file according to any one of claims 1-4.
Citation Information
Patent Citations
Network electronic data collecting, curing, verifying and restoring method and system
CN104378325A
Method and device for efficiently recompressing file
CN105468754A