You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Size returns the number of bytes of the stream.func (k*Stream) Size() (int64, error) {
// Go has no internal ReadSeeker function to get current ReadSeeker size,// thus we use the following trick.// Remember our current positioncurPos, err:=k.Pos()
iferr!=nil {
return0, err
}
// Seek to the end of the File object_, err=k.Seek(0, io.SeekEnd)
iferr!=nil {
return0, err
}
// Remember position, which is equal to the full lengthfullSize, err:=k.Pos()
iferr!=nil {
returnfullSize, err
}
// Seek back to the current position_, err=k.Seek(curPos, io.SeekStart)
returnfullSize, err
}
It seems that if the assignment fullSize, err := k.Pos() returns an error the current position pointer is never set to its original value.
A potential mitigation of the problem could be:
// Size returns the number of bytes of the stream.func (k*Stream) Size() (int64, error) {
// Go has no internal ReadSeeker function to get current ReadSeeker size,// thus we use the following trick.// Remember our current positioncurPos, err:=k.Pos()
iferr!=nil {
return0, err
}
// Deferred seek back to the current positiondeferk.Seek(curPos, io.SeekStart)
// Seek to the end of the File object_, err=k.Seek(0, io.SeekEnd)
iferr!=nil {
return0, err
}
// return position, which is equal to the full lengthreturnk.Pos()
}
The text was updated successfully, but these errors were encountered:
The current implementation of
Stream.Size()
is:It seems that if the assignment
fullSize, err := k.Pos()
returns an error the current position pointer is never set to its original value.A potential mitigation of the problem could be:
The text was updated successfully, but these errors were encountered: