当前位置:网站首页>go 断点续传
go 断点续传
2022-06-24 06:32:00 【给我一瓶冰阔洛】
package main
import (
"fmt"
"os"
"strconv"
"io"
)
func main() {
//文件目录
srcFile:="E:\\企业级四层负载均衡lVS\\L100 - 企业级开源四层负载均衡解决方案-LVS(完整版) - 199元\\第1章 课程简介\\1-1 LVS导学视频.mp4"
//拷贝目录
destFile:="E:\\cpoy\\LVS第一章.mp4"
//临时目录
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.读取临时文件中的数据,根据seek
// Seek 设置文件指针偏移量
file3.Seek(0,io.SeekStart)
bs:=make([]byte,100,100)
// read 读取 len(bs) 字节
n1,err:=file3.Read(bs)
fmt.Printf("读取字节大小%v\n",n1)
countStr:=string(bs[:n1])
fmt.Printf("转换为字符串%v\n",countStr)
//count,_:=strconv.Atoi(countStr)
count,_:=strconv.ParseInt(countStr,10,64)
fmt.Printf("转换为INT64%v\n",count)
//2. 设置读,写的偏移量
file1.Seek(count,0)
file2.Seek(count,0)
data:=make([]byte,1024,1024)
n2:=-1// 读取的数据量
n3:=-1//写出的数据量
total :=int(count)//读取的总量
for{
//3.读取数据
n2,err=file1.Read(data)
if err ==io.EOF{
fmt.Println("文件复制完毕。。")
file3.Close()
os.Remove(tempFile)
break
}
//将数据写入到目标文件
n3,_=file2.Write(data[:n2])
total += n3
//将复制总量,存储到临时文件中
file3.Seek(0,io.SeekStart)
file3.WriteString(strconv.Itoa(total))
//假装断电
if total>8000000{
panic("假装断电了。。。,假装的。。。")
}
}
}
边栏推荐
- Overview of new features in mongodb5.0
- Discussion on NFT Technology
- Free and easy-to-use screen recording and video cutting tool sharing
- Could not read username for xxxxx
- Why computers often crash
- Analysis and treatment of easydss flash back caused by system time
- Application of O & M work order
- Koa source code analysis
- What transmission modes does the IOT data gateway support
- Continuously evolving cloud native application delivery
猜你喜欢
![[fault announcement] one stored procedure brings down the entire database](/img/7c/e5adda73a077fe4b8f04b59d1e0e1e.jpg)
[fault announcement] one stored procedure brings down the entire database

Technology is a double-edged sword, which needs to be well kept

The product layout is strengthened, the transformation of digital intelligence is accelerated, and FAW Toyota has hit 2022million annual sales

ServiceStack. Source code analysis of redis (connection and connection pool)
Oracle case: ohasd crash on AIX

Enter the software test pit!!! Software testing tools commonly used by software testers software recommendations

【二叉树】——二叉树中序遍历

A cigarette of time to talk with you about how novices transform from functional testing to advanced automated testing
Fault analysis | using --force to batch import data leads to partial data loss

解读AI机器人产业发展的顶层设计
随机推荐
What is a secondary domain name primary domain name how to apply for a secondary domain name
The difference between ArrayList and LinkedList and the principle of using scene locality
DHCP server setup
What I regret most when I learn programming!
From home to Ali, a year for junior students to apply for jobs
Water conservancy RTU telemetry terminal
Provide SFTP connection for Amazon S3
TensorFlow 2 quickstart for beginners
Talk about the story behind search engines
Tencent cloud VPC machine, no image when installing monitoring components
Continuously evolving cloud native application delivery
What is Druid
Semantic web, semantic web, linked data and knowledge map
Replacing human eyes -- visual inspection technology
Excel data extraction technique: a universal formula for extracting numbers from mixed text
Analysis of official template of wechat personnel recruitment management system (II)
SQL server memory management on cloud
A cigarette of time to talk with you about how novices transform from functional testing to advanced automated testing
Project deployment for learning 3D visualization from scratch
Authoritative recognition! Tencent cloud data security Zhongtai was selected as the 2021 pioneer practice case