// 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
}