CN102880677A - File packing and reading method based on Hash - Google Patents

File packing and reading method based on Hash Download PDF

Info

Publication number
CN102880677A
CN102880677A CN2012103339070A CN201210333907A CN102880677A CN 102880677 A CN102880677 A CN 102880677A CN 2012103339070 A CN2012103339070 A CN 2012103339070A CN 201210333907 A CN201210333907 A CN 201210333907A CN 102880677 A CN102880677 A CN 102880677A
Authority
CN
China
Prior art keywords
file
hash
package
path
packing
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN2012103339070A
Other languages
Chinese (zh)
Other versions
CN102880677B (en
Inventor
陈飞舟
吴才忠
刘畅
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Chengdu Xishanju Interactive Entertainment Technology Co Ltd
Zhuhai Kingsoft Digital Network Technology Co Ltd
Original Assignee
Zhuhai Kingsoft Online Game Technology Co Ltd
Chengdu Xishanju Interactive Entertainment Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhuhai Kingsoft Online Game Technology Co Ltd, Chengdu Xishanju Interactive Entertainment Technology Co Ltd filed Critical Zhuhai Kingsoft Online Game Technology Co Ltd
Priority to CN201210333907.0A priority Critical patent/CN102880677B/en
Publication of CN102880677A publication Critical patent/CN102880677A/en
Application granted granted Critical
Publication of CN102880677B publication Critical patent/CN102880677B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

The invention discloses a file packing and reading method based on Hash. The packing method comprises the steps as follows: reading files required to be packed in sequence; calculating the Hash values of the paths of the files; writing the files into a file data region; writing the Hash values and the offset values of the files into a Hash table; and finishing the writing operation of all the files. The reading method comprises the steps as follows: obtaining the Hash values of the paths of the files in the packs through read-in file index information; searching the corresponding offset values in the Hash table; and reading data files corresponding to the offset values in the file data region. According to the file packing and reading method, the identifications of the files in the packs adopt the Hash values and the string matching operation does not need to be performed in the search process; the indexes adopt the Hash table, so that the offset addresses can be quickly positioned; and the original directory structure cannot be recovered through the files in the packs. The file packing and reading method can be widely applied to the field of computer software.

Description

A kind of file packing and read method based on Hash
Technical field
The present invention relates to a kind of file packing and read method, especially a kind of file packing and read method based on Hash.
Background technology
Existing software client resource adopts the packing manner storage usually, thereby obtains that transmission is convenient, resource is maintained secrecy and the advantage such as fast access speed more.In packing process, because traditional indexed modes such as employing two minutes or B+ trees, its index speed is still waiting to promote; Simultaneously, because the conventional bag file uses the file path name as the unique identification of package-in file, need to carry out comparing one by one of character in the word string in the index comparison procedure, relatively consuming time.In reading process, because index information has been stored the routing information of package-in file in the APMB package, malicious user can reduce the bibliographic structure of packing preceding document fully by these information, and this has brought potential safety hazard to software product.
Summary of the invention
In order to solve the problems of the technologies described above, the technical solution adopted in the present invention is: a kind of file packing method based on Hash, and packaging method may further comprise the steps:
A, read the file of required packing successively;
The cryptographic hash of B, the above-mentioned file path of calculating;
C, above-mentioned file is write file data district in the APMB package;
D, the off-set value of the cryptographic hash of file path and file is write Hash table in the APMB package;
E, judge whether to have read the file that all need be packed, if not, then continue execution in step A, if, the then packing of ends file.
Further, step B comprises following substep:
B1, calculation document path cryptographic hash;
B2, judge whether hash-collision;
If there is not hash-collision in B3, then continue execution in step C; If there is hash-collision, then change hash algorithm or file path title after, get back to step B1 and re-execute.
Further, do not preserve routing information, bibliographic structure or the filename of package-in file in the APMB package.
In order to solve the problems of the technologies described above, another technical scheme of the present invention is: a kind of file reading based on Hash, and read method may further comprise the steps:
F, the instrument that reads receive the index information of the required file that reads from upper layer application, the cryptographic hash in the path by file index acquisition of information package-in file;
G, in Hash table, search off-set value corresponding to cryptographic hash;
H, the file data district in APMB package read the data file corresponding with off-set value.
Further, the file index information in the step F is the path of package-in file.
Further, the file index information in the step F is the cryptographic hash in the path of package-in file.
The invention has the beneficial effects as follows: adopt packaging method of the present invention, each file in the cryptographic hash unique identification bag in the APMB package, Hash table is preserved the corresponding relation of cryptographic hash and off-set value, read package-in file and do not need to carry out the word string coupling, only can from Hash table, locate fast the offset information of concrete package-in file by the cryptographic hash of identification document, improve greatly reading speed.
Another beneficial effect of the present invention is: adopt read method of the present invention, compare with reading manner in the past, reading in the process not to need to use file path, thereby malicious user can't restore by the file after the packing the front original directory structure of packing.
Description of drawings
Fig. 1 is the rear resulting file bag schematic diagram of packing among the present invention;
Fig. 2 is the block diagram of packing process among the present invention;
Fig. 3 is the substep figure of step B in the packing process shown in Figure 2;
Fig. 4 is the block diagram that reads process among the present invention.
Embodiment
Below in conjunction with accompanying drawing the specific embodiment of the present invention is described further:
A kind of file packing and read method based on Hash namely is by packing process and read packet procedures and then finish writing and read operation package-in file.
With reference to the APMB package among Fig. 1, packing process is about to file and is written to process in the APMB package, and it is finished by strapping tool.Strapping tool receives following input message:
1, the file directory of required packing or listed files;
2, employed hash algorithm;
3, the way of output and outgoing position.
With reference to Fig. 2, a kind of file packing method based on Hash, described packaging method may further comprise the steps:
A, read the file of required packing successively;
Strapping tool reads corresponding file according to input message from disk, and then generates corresponding file bag.The file bag include file data field that generates and two parts of Hash table.The file data district provides the place for the package-in file storage, and wherein each package-in file is called the off-set value of this package-in file in the position in file data district.
The cryptographic hash of B, the above-mentioned file path of calculating;
Preserve the corresponding relation of each cryptographic hash and off-set value in the Hash table, be used for reading packet procedures file is carried out fast finding.
C, file is write file data district in the APMB package.
D, the off-set value of the cryptographic hash of file path and file is write Hash table in the APMB package;
When All Files when all writing in files data field and all cryptographic hash are identical, then this moment is with the key of cryptographic hash as Hash table.
E, judge whether to have read the file that all need be packed, if not, then continue execution in step A, if, the then packing of ends file.
If read the file that all need be packed, then the file packing process finishes, and obtains file bag as shown in Figure 1.
With reference to Fig. 3, strapping tool reads the file of needs packing according to file directory or listed files, and the file that reads is written in the file data district, and records at this moment the position of file in the data field, and this position i.e. the off-set value of file for this reason.Use afterwards the hash algorithm of appointment, for file path calculates cryptographic hash.
Be further used as preferred embodiment, described step B comprises following substep:
B1, calculation document path cryptographic hash;
B2, judge whether hash-collision;
If there is not hash-collision in B3, then continue execution in step C; If there is hash-collision, then change hash algorithm or file path title after, get back to step B1 and re-execute.
If this cryptographic hash is not identical with all cryptographic hash that All Files before calculated, then can be with the sign of this value as file.If any cryptographic hash of calculating of preceding document is identical with it for this cryptographic hash, then require to change hash algorithm or revise packaged file path.Otherwise packing process can't continue.
Be further used as preferred embodiment, do not preserve routing information, bibliographic structure or the filename of package-in file in the described APMB package.
With reference to Fig. 4, a kind of file reading based on Hash is read packet procedures and is finished by corresponding client-side program, and described read method may further comprise the steps:
F, the instrument that reads receive the index information of the required file that reads from upper layer application, the cryptographic hash in the path by file index acquisition of information package-in file;
G, in Hash table, search off-set value corresponding to cryptographic hash;
H, the file data district in APMB package read data file corresponding to off-set value.
Its reading manner to package-in file is divided into two kinds:
1. read by file path;
2. the cryptographic hash by file path reads.Two kinds of file index information that APMB package reads are specified by client configuration item or parameter.
Be further used as preferred embodiment, the file index information in the described step F is the path of package-in file, and the cryptographic hash in the path of described package-in file calculates by corresponding hash algorithm.Be the required file path that reads that client imports into, and use hash algorithm identical when packing to calculate the cryptographic hash of this file path.Through after calculating cryptographic hash, can in Hash table, find out the off-set value of this package-in file.Read the file of off-set value position, namely finish file and read.
Be further used as preferred embodiment, the file index information in the described step F is the cryptographic hash in the path of package-in file.Adopt the cryptographic hash of file path to read, then client imports the required file path cryptographic hash that reads into.After obtaining this cryptographic hash, directly in Hash table, search, get final product to get the off-set value of this package-in file.Read the file of off-set value position, namely finish file and read.
More than be that better enforcement of the present invention is specified, but the invention is not limited to described embodiment, those of ordinary skill in the art can also make all equivalents or replacement under the prerequisite of spirit of the present invention, the conversion that these are equal to or replacement all are included in the application's claim limited range.

Claims (6)

1. file packing method based on Hash, it is characterized in that: this packaging method may further comprise the steps:
A, read the file of required packing successively;
The cryptographic hash of B, the above-mentioned file path of calculating;
C, above-mentioned file is write file data district in the APMB package;
D, the off-set value of the cryptographic hash of file path and file is write Hash table in the APMB package;
E, judge whether to have read the file that all need be packed, if not, then continue execution in step A, if, the then packing of ends file.
2. a kind of file packing method based on Hash according to claim 1, it is characterized in that: described step B comprises following substep:
B1, calculation document path cryptographic hash;
B2, judge whether hash-collision;
If there is not hash-collision in B3, then continue execution in step C; If there is hash-collision, then change hash algorithm or file path title after, get back to step B1 and re-execute.
3. a kind of file packing method based on Hash according to claim 1 and 2 is characterized in that: routing information, bibliographic structure or the filename of not preserving package-in file in the described APMB package.
4. file reading based on Hash, it is characterized in that: this read method may further comprise the steps:
F, the instrument that reads receive the index information of the required file that reads from upper layer application, the cryptographic hash in the path by file index acquisition of information package-in file;
G, in Hash table, search off-set value corresponding to cryptographic hash;
H, the file data district in APMB package read the data file corresponding with off-set value.
5. a kind of file reading based on Hash according to claim 4, it is characterized in that: the file index information in the described step F is the path of package-in file.
6. a kind of file reading based on Hash according to claim 4, it is characterized in that: the file index information in the described step F is the cryptographic hash in the path of package-in file.
CN201210333907.0A 2012-09-11 2012-09-11 A kind of packing of the file based on Hash and read method Active CN102880677B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201210333907.0A CN102880677B (en) 2012-09-11 2012-09-11 A kind of packing of the file based on Hash and read method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201210333907.0A CN102880677B (en) 2012-09-11 2012-09-11 A kind of packing of the file based on Hash and read method

Publications (2)

Publication Number Publication Date
CN102880677A true CN102880677A (en) 2013-01-16
CN102880677B CN102880677B (en) 2016-04-13

Family

ID=47482003

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201210333907.0A Active CN102880677B (en) 2012-09-11 2012-09-11 A kind of packing of the file based on Hash and read method

Country Status (1)

Country Link
CN (1) CN102880677B (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104572876A (en) * 2014-12-19 2015-04-29 珠海金山网络游戏科技有限公司 Method and device for reading configuration file corresponding to software
CN106294352A (en) * 2015-05-13 2017-01-04 姚猛 A kind of document handling method, device and file system
CN107402788A (en) * 2017-07-25 2017-11-28 网易(杭州)网络有限公司 Resource packing management method and device
CN107633088A (en) * 2017-09-29 2018-01-26 深圳市金证科技股份有限公司 A kind of file management method and device
CN108509209A (en) * 2018-04-08 2018-09-07 平安普惠企业管理有限公司 A kind of generation method, device, computer equipment and the storage medium of resource packet

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101226546A (en) * 2008-02-01 2008-07-23 华为技术有限公司 Method for organizing and searching document
CN101373473A (en) * 2008-09-03 2009-02-25 北京星网锐捷网络技术有限公司 Method and system for reducing file quantity in embedded system flash memory
CN101957861A (en) * 2010-10-18 2011-01-26 江苏大学 Novel metadata server cluster and metadata management method based on reconciliation statement
CN102609509A (en) * 2010-04-26 2012-07-25 华为技术有限公司 Method and device for processing hash data

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101226546A (en) * 2008-02-01 2008-07-23 华为技术有限公司 Method for organizing and searching document
CN101373473A (en) * 2008-09-03 2009-02-25 北京星网锐捷网络技术有限公司 Method and system for reducing file quantity in embedded system flash memory
CN102609509A (en) * 2010-04-26 2012-07-25 华为技术有限公司 Method and device for processing hash data
CN101957861A (en) * 2010-10-18 2011-01-26 江苏大学 Novel metadata server cluster and metadata management method based on reconciliation statement

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104572876A (en) * 2014-12-19 2015-04-29 珠海金山网络游戏科技有限公司 Method and device for reading configuration file corresponding to software
CN106294352A (en) * 2015-05-13 2017-01-04 姚猛 A kind of document handling method, device and file system
CN106294352B (en) * 2015-05-13 2019-10-25 姚猛 A kind of document handling method, device and file system
CN107402788A (en) * 2017-07-25 2017-11-28 网易(杭州)网络有限公司 Resource packing management method and device
CN107402788B (en) * 2017-07-25 2020-09-25 网易(杭州)网络有限公司 Resource packaging management method and device
CN107633088A (en) * 2017-09-29 2018-01-26 深圳市金证科技股份有限公司 A kind of file management method and device
CN107633088B (en) * 2017-09-29 2020-04-24 深圳市金证科技股份有限公司 File management method and device
CN108509209A (en) * 2018-04-08 2018-09-07 平安普惠企业管理有限公司 A kind of generation method, device, computer equipment and the storage medium of resource packet

Also Published As

Publication number Publication date
CN102880677B (en) 2016-04-13

Similar Documents

Publication Publication Date Title
EP3561674B1 (en) Method and apparatus for verifying block data in a blockchain
US9292217B2 (en) Logical volume space sharing
CN102880677B (en) A kind of packing of the file based on Hash and read method
US8281153B2 (en) Method for indexing encrypted column
CN106663047A (en) Systems and methods for oprtimized signature comparisons and data replication
CN104091129B (en) A kind of data processing method and device
JP2006024218A5 (en)
CN105824881B (en) A kind of data de-duplication data placement method based on load balancing
WO2016171271A1 (en) Encrypted database system and encrypted data management method
US8977662B1 (en) Storing data objects from a flat namespace in a hierarchical directory structured file system
CN106326309A (en) Data query method and device
WO2014110940A1 (en) A method, apparatus and system for storing, reading the directory index
CN104424225B (en) Document handling method based on document transmission process and device
CN106294826A (en) A kind of company-data Query method in real time and system
Liang et al. Mid-model design used in model transition and data migration between relational databases and nosql databases
CN104834650A (en) Method and system for generating effective query tasks
CN106557571A (en) A kind of data duplicate removal method and device based on K V storage engines
CN103810246A (en) Index building method and device and index query method and device
CN107992763B (en) Power failure protection method and device for file system
CN102902701B (en) Information query system and method
CN112417225A (en) Joint query method and system for multi-source heterogeneous data
CN106295402A (en) The hidden method of a kind of dll file and system
TW201737065A (en) Remote command processing method and device
CN106874457B (en) Method for improving metadata cluster performance through virtual directory
CN106934066A (en) A kind of metadata processing method, device and storage device

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
CP03 Change of name, title or address
CP03 Change of name, title or address

Address after: 519000 Room 102, 202, 302 and 402, No. 325, Qiandao Ring Road, Tangjiawan Town, high tech Zone, Zhuhai City, Guangdong Province, Room 102 and 202, No. 327 and Room 302, No. 329

Patentee after: Zhuhai Jinshan Digital Network Technology Co.,Ltd.

Patentee after: CHENGDU XISHANJU INTERACTIVE ENTERTAINMENT TECHNOLOGY Co.,Ltd.

Address before: 519000 Jinshan software building, 8 Lanshan lane, Jida Jingshan Hill Road, Zhuhai, Guangdong

Patentee before: ZHUHAI KINGSOFT ONLINE GAME TECHNOLOGY Co.,Ltd.

Patentee before: CHENGDU XISHANJU INTERACTIVE ENTERTAINMENT TECHNOLOGY Co.,Ltd.