func (v *View) Truncate(length int64) {
	if length < 0 || length >= v.size {
		return // Nothing to do.
	}
	for buf := v.data.Back(); buf != nil && v.size > length; buf = v.data.Back() {
		l := int64(buf.write - buf.read) // Local bytes.
		switch {
		case v.size-l >= length:
			// Drop the buffer completely; see above.
			v.data.Remove(buf)
			v.size -= l
			buf.Reset()
			bufferPool.Put(buf)

		case v.size > length && v.size-l < length:
			// Just truncate the buffer locally.
			delta := (length - (v.size - l))
			buf.write = buf.read + int(delta)
			v.size = length

		default:
			// Should never happen.
			panic("invalid buffer during truncation")
		}
	}
	v.size = length // Save the new size.
}
// Truncate truncates the view to the given bytes.
Truncate truncates the view to the given bytes.
// Truncate truncates the view to the given bytes .
func (v *View) Truncate(length int64) {
	if length < 0 || length >= v.size {
		return 
	}
	for buf := v.data.Back(); buf != nil && v.size > length; buf = v.data.Back() {
		l := int64(buf.write - buf.read) 
		switch {
		case v.size-l >= length:
			v.data.Remove(buf)
			v.size -= l
			buf.Reset()
			bufferPool.Put(buf)
		case v.size > length && v.size-l < length:
			delta := (length - (v.size - l))
			buf.write = buf.read + int(delta)
			v.size = length
		default:
			panic("invalid buffer during truncation")
		}
	}
	v.size = length 
}
func ( v * View ) Truncate ( length int64 ) { if length < 0 || length >= v . size { return } for buf := v . data . Back ( ) ; buf != nil && v . size > length ; buf = v . data . Back ( ) { l := int64 ( buf . write - buf . read ) switch { case v . size - l >= length : v . data . Remove ( buf ) v . size -= l buf . Reset ( ) bufferPool . Put ( buf ) case v . size > length && v . size - l < length : delta := ( length - ( v . size - l ) ) buf . write = buf . read + int ( delta ) v . size = length default : panic ( " " ) } } v . size = length }
Truncate truncates the view to the given bytes.
Truncate truncates the view to the given bytes .
// Nothing to do. // Local bytes. // Drop the buffer completely; see above. // Just truncate the buffer locally. // Should never happen. // Save the new size.