blob: 64c4fce448d061f6b191d4dcb210d43d17023b28 [file] [log] [blame]
// Copyright 2016 The Upspin 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 internal provides some helpers used by packing implementations.
package internal
// LazyBuffer is a []byte that is lazily (re-)allocated when its
// Bytes method is called.
type LazyBuffer []byte
// Bytes returns a []byte that has length n. It re-uses the underlying
// LazyBuffer []byte if it is at least n bytes in length.
func (b *LazyBuffer) Bytes(n int) []byte {
if *b == nil || len(*b) < n {
*b = make([]byte, n)
}
return (*b)[:n]
}