首页 > 编程知识 正文

linux,tar解压会覆盖现有文件吗

时间:2023-05-06 10:55:08 阅读:17482 作者:1523

对于gz压缩文件,这是对gz压缩文件的处理,而不是gz、gz、gz、zip、gzip和rar。

工作场景:需要解压缩gz压缩文件内存,处理读取处理后保存在存储介质中; 复制处理非gz压缩文件。

导入(

' bytes '

' compress/gzip '

' fmt '

' io '

' io/ioutil '

操作系统

' strings '

//inFilename gz压缩文件完整路径outFilename输出的压缩文件完整路径

funcfixfiledata(infilename,outfilename字符串) error {

w,err :=操作系统. create (outfilename ) ) ) ) ) ) ) )。

if err!=nil {

FMT.println('crateerror: ',err.Error ) )

返回错误

}

defer w.Close (

处理ifstrings.Hassuffix(infilename,'.gz ' )//压缩文件

fr,err:=OS.open(infilename ) )。

if err!=nil {

返回错误

}

defer fr.Close (

gzReader,err:=gzip.newreader(fr ) ) ) ) )。

if err!=nil {

返回错误

}

defer gzReader.Close (

gzContext,err :=I outil.read all (gz reader ) ) ) ) ) ) ) 65

if err!=nil {

返回错误

}

var writeContext bytes.Buffer

写上下文. reset (

context :=字符串(gz context )

con lines :=strings.split (上下文,'n ' ) )。

for _,valueLine :=range conLines {

line split :=strings.split (值行,列分隔符)。

//业务处理

value line=strings.replace (value line,' old ',' new ',-1) )。

write context.writestring (value line 'n ' ) )。

}

writer:=gzip.newwriter(w ) )

defer writer.Close (

_,err=writer.write (write context.bytes ()

if err!=nil {

返回错误

}

} else {

rc,err:=OS.open(infilename ) )。

if err!=nil {

返回错误

}

defer rc.Close () )。

_,err=io.copy(w,rc ) )。

if err!=nil {

返回错误

}

}

返回Nil

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。