mirror of
https://github.com/vbatts/tar-split.git
synced 2024-11-22 16:15:39 +00:00
archive/tar: a []byte copy needed for GNU LongLink
This commit is contained in:
parent
9b9df04f1f
commit
4d66163297
1 changed files with 10 additions and 22 deletions
|
@ -154,60 +154,48 @@ func (tr *Reader) Next() (*Header, error) {
|
|||
}
|
||||
return hdr, nil
|
||||
case TypeGNULongName:
|
||||
var b *bytes.Buffer
|
||||
if tr.RawAccounting {
|
||||
b = bytes.NewBuffer(tr.RawBytes())
|
||||
}
|
||||
// We have a GNU long name header. Its contents are the real file name.
|
||||
realname, err := ioutil.ReadAll(tr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var buf []byte
|
||||
if tr.RawAccounting {
|
||||
if _, err = tr.rawBytes.Write(b.Bytes()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err = tr.rawBytes.Write(realname); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b.Reset()
|
||||
b.Write(tr.RawBytes())
|
||||
buf = make([]byte, tr.rawBytes.Len())
|
||||
copy(buf[:], tr.RawBytes())
|
||||
}
|
||||
hdr, err := tr.Next()
|
||||
// since the above call to Next() resets the buffer, we need to throw the bytes over
|
||||
if tr.RawAccounting {
|
||||
b.Write(tr.RawBytes())
|
||||
if _, err = tr.rawBytes.Write(b.Bytes()); err != nil {
|
||||
buf = append(buf, tr.RawBytes()...)
|
||||
if _, err = tr.rawBytes.Write(buf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
hdr.Name = cString(realname)
|
||||
return hdr, err
|
||||
case TypeGNULongLink:
|
||||
var b *bytes.Buffer
|
||||
if tr.RawAccounting {
|
||||
b = bytes.NewBuffer(tr.RawBytes())
|
||||
}
|
||||
// We have a GNU long link header.
|
||||
realname, err := ioutil.ReadAll(tr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var buf []byte
|
||||
if tr.RawAccounting {
|
||||
if _, err = tr.rawBytes.Write(b.Bytes()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err = tr.rawBytes.Write(realname); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b.Reset()
|
||||
b.Write(tr.RawBytes())
|
||||
buf = make([]byte, tr.rawBytes.Len())
|
||||
copy(buf[:], tr.RawBytes())
|
||||
}
|
||||
hdr, err := tr.Next()
|
||||
// since the above call to Next() resets the buffer, we need to throw the bytes over
|
||||
if tr.RawAccounting {
|
||||
b.Write(tr.RawBytes())
|
||||
if _, err = tr.rawBytes.Write(b.Bytes()); err != nil {
|
||||
buf = append(buf, tr.RawBytes()...)
|
||||
if _, err = tr.rawBytes.Write(buf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue