Second-binary dual-channel technology implementation file segmentation (1)

xiaoxiao2021-03-06  57

(1) Programming principle:?

The file segmentation is actually the method of binary reading and writing target files, accurately saved as a separate file, in general, the divided file cannot be used before the correct assembly is assembled. ?

The file restore is the reverse process of file segmentation, that is, written to a divided file in segmentation sequential reading and writing, as long as the program algorithm and the logic are correct, and after segmentation and division The file is no one byte. ?

The reason why the use of dual channel technology is because when the divided file is large or very large (far greater than the memory), the memory two-binding buffer buffer using a single file channel is very easy to cause the exhaustion of the operation, and the other Aspects, its processing speed and reliability are also very worrying. ?

Programming idea is, first dividing the target file into a specified size file using dual channel technology, the extension is "specified file name . Source file extension . Segmentation serial number", and generates a restore information file "Split file name .hj ", the file will record information about file segmentation; when the file is restored, the dual channel is also utilized. According to the information registered in the restore information file, the file to be restored is written to the same file. ?

(2) Programming practice:?

(1) Start VB6, create a standard EXE project, add a form FORM1, add a Microsoft? Common? Dialog? Control? 6.0 control, named COD1; add two Frame control (Frame1 CAPTION = "file segmentation", frame2 CAPTION = "File Restore"); Add five label boxes, the CAPTION property is "divided by the file name", "Split file size", "Split file", "unit: Bytes byte", " Restore Information File Name "," Restore file saved "; Add four caption =" Browse ... "command button Command1, Command2, Command3, Command4; Add 5 TextBox from top to bottom. Button TXTFileName, TXTFileLength, txtoutname, txttemplatename, txtoutputfile; add two command buttons cmdsplit, caption = "Start Split", cmdunsplit, caption = "Start Restore"; two commands Press Command5, Command6 to indicate the progress of the operation. code show as below:?

OPTION? EXPLICIT?

PRIVATE? SUB? CMDSPLIT_CLICK ()? 'File segmentation?

DIM? Err_DESCR? AS? STRING? 'Defines a string variable that receives the return error code?

IF? Not? Splitfile (txtFilename.text, 0, err_descr, clng (txtFileLength.Text), txtoutname.text)?

MSGBOX? "File operation creates an error -"? &? Err_descr, vbexclamation?

Else?

MSGBOX? "File segmentation operation has been successfully completed!"?

END? IF?

END? SUB? 'When the splitfile utility return value = true indicates the operation, otherwise failed and returned the error short tip?

PRIVATE? SUB? Cmdunsplit_click ()? 'File Restore?

DIM? ERR_DESCR? AS? STRING?

IF? Not? Reassemblefile (txt? Templatename.text, false, txtoutputfile.text)? THEN?

MSGBOX? "File operation creates an error -"? &? Err_descr, vbexclamation? Else?

MSGBOX? "The file restore operation has been successfully completed!"?

END? IF?

END? SUB? 'When the REASSEMBLEFILE utility return value = true indicates that the operation is successful, otherwise failed and returned the error short message?

PRIVATE? SUB? COMMAND1_CLICK ()? 'Select the split file?

COD1.FILTER = "All format files *. * | *. *"?

COD1.SHOWOPEN?

IF? COD1.FILENAME <> "" THEN?

TXTFILENAME.TEXT = COD1.FILENAME?

End? If? 'If the file is exited if the file is not selected?

END? SUB?

PRIVATE? SUB? COMMAND2_CLICK ()? 'Document Save Path Name after segmentation?

WITH? COD1?

IF? TxtFilename.text = ""???

MSGBOX? "Please select a split file!"?

EXIT? SUB?

End? If? 'If the split file exits is not selected?

.Showsave?

If? .Filename <> "" "??

TXTOUTNAME.TEXT = .filename?

End? If? 'If you do not specify a save file name to exit?

END? WITH?

END? SUB?

PRIVATE? SUB? COMMAND3_CLICK ()? 'Recycled the restore information file name?

WITH? COD1?

.Filename = ""?

.Filter = "Restore information file * .hj | * .hj"? 'Only display * .hj restore information file?

.Showopen?

If? .Filename <> "" "??

TXTTEMPLATENAME.TEXT = .filename?

END? IF?

END? WITH?

END? SUB?

PRIVATE? SUB? COMMAND4_CLICK ()? 'Get and calculates the restore file name, extension?

DIM? G?

WITH? COD1?

If? Txttemplatingname.text = ""???

MSGBOX? "Please select a restore information file!"?

EXIT? SUB? 'If the restore information file is not selected, exit the process?

END? IF?

.Filter = ""?

.Filename = "" "Clear expiration file name and type pointer?

.Showsave?

If? .Filename <> "" "??

g = INSTR (1, txttemplatename.text, ".")? 'Find the first "."

TXTOUTPUTFILE.TEXT = .filename? &? MID?

(TXTTEMPLATENAME.TEXT, G, 4)? 'Return to the user specifies the name and original extension?

END? IF?

END? WITH?

END? SUB?

PRIVATE? SUB? FORM_LOAD ()?

Me.Left = (Screen.width-me.width / 2?

Me.Top = (Screen.height-me.height) / 2? 'Form in the form?

Me.caption = app.title? 'Initializing the title bar?

END? SUB? 'Over the main program?

转载请注明原文地址:https://www.9cbs.com/read-118268.html

New Post(0)