当前位置:网站首页>Go breakpoint continuation

Go breakpoint continuation

2022-06-24 06:41:00 Give me a bottle of ice cream

package main

import (
	"fmt"
	"os"
	"strconv"
	"io"
)

func main() {
	// File directory 
	srcFile:="E:\\ Enterprise level Four layer load balancing lVS\\L100 -  Enterprise level open source four layer load balancing solution -LVS( Full version ) - 199 element \\ The first 1 Chapter   Course introduction \\1-1 LVS Learning guide video .mp4"
	// replica catalog 
	destFile:="E:\\cpoy\\LVS Chapter one .mp4"
	// Temporary directory 
	tempFile:=destFile+"temp.txt"
	file1,_:=os.Open(srcFile)
	file2,_:=os.OpenFile(destFile,os.O_CREATE|os.O_WRONLY,os.ModePerm)
	file3,_:=os.OpenFile(tempFile,os.O_CREATE|os.O_RDWR,os.ModePerm)

	defer file1.Close()
	defer file2.Close()
	//1. Read the data in the temporary file , according to seek
	// Seek  Set file pointer offset 
	file3.Seek(0,io.SeekStart)
	bs:=make([]byte,100,100)
	// read   Read  len(bs)  byte 
	n1,err:=file3.Read(bs)
	fmt.Printf(" Read byte size %v\n",n1)

	countStr:=string(bs[:n1])
	fmt.Printf(" Convert to string %v\n",countStr)
	//count,_:=strconv.Atoi(countStr)
	count,_:=strconv.ParseInt(countStr,10,64)
	fmt.Printf(" Convert to INT64%v\n",count)
	//2.  Set read , Write offset 
	file1.Seek(count,0)
	file2.Seek(count,0)
	data:=make([]byte,1024,1024)
	n2:=-1//  Amount of data read 
	n3:=-1// Amount of data written 
	total :=int(count)// Total number of reads 

	for{
		//3. Reading data 
		n2,err=file1.Read(data)
		if err ==io.EOF{
			fmt.Println(" File copy complete ..")
			file3.Close()
			os.Remove(tempFile)
			break
		}
		// Write data to the target file 
		n3,_=file2.Write(data[:n2])
		total += n3
		// The total number of copies , Store in a temporary file 
		file3.Seek(0,io.SeekStart)
		file3.WriteString(strconv.Itoa(total))


		// Fake power failure 
		if total>8000000{
		panic(" Pretend to be out of power ..., Pretend ...")
		}
	}

}

原网站

版权声明
本文为[Give me a bottle of ice cream]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206240009059852.html