Source File
writer.go
Belonging Package
testing/iotest
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package iotest
import
// TruncateWriter returns a Writer that writes to w
// but stops silently after n bytes.
func ( io.Writer, int64) io.Writer {
return &truncateWriter{, }
}
type truncateWriter struct {
w io.Writer
n int64
}
func ( *truncateWriter) ( []byte) ( int, error) {
if .n <= 0 {
return len(), nil
}
// real write
= len()
if int64() > .n {
= int(.n)
}
, = .w.Write([0:])
.n -= int64()
if == nil {
= len()
}
return
}
The pages are generated with Golds v0.7.0-preview. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |