diff options
Diffstat (limited to 'vendor/github.com/ulikunitz/xz/lzma/bytewriter.go')
-rw-r--r-- | vendor/github.com/ulikunitz/xz/lzma/bytewriter.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/vendor/github.com/ulikunitz/xz/lzma/bytewriter.go b/vendor/github.com/ulikunitz/xz/lzma/bytewriter.go new file mode 100644 index 0000000..a3696ba --- /dev/null +++ b/vendor/github.com/ulikunitz/xz/lzma/bytewriter.go | |||
@@ -0,0 +1,37 @@ | |||
1 | // Copyright 2014-2017 Ulrich Kunitz. All rights reserved. | ||
2 | // Use of this source code is governed by a BSD-style | ||
3 | // license that can be found in the LICENSE file. | ||
4 | |||
5 | package lzma | ||
6 | |||
7 | import ( | ||
8 | "errors" | ||
9 | "io" | ||
10 | ) | ||
11 | |||
12 | // ErrLimit indicates that the limit of the LimitedByteWriter has been | ||
13 | // reached. | ||
14 | var ErrLimit = errors.New("limit reached") | ||
15 | |||
16 | // LimitedByteWriter provides a byte writer that can be written until a | ||
17 | // limit is reached. The field N provides the number of remaining | ||
18 | // bytes. | ||
19 | type LimitedByteWriter struct { | ||
20 | BW io.ByteWriter | ||
21 | N int64 | ||
22 | } | ||
23 | |||
24 | // WriteByte writes a single byte to the limited byte writer. It returns | ||
25 | // ErrLimit if the limit has been reached. If the byte is successfully | ||
26 | // written the field N of the LimitedByteWriter will be decremented by | ||
27 | // one. | ||
28 | func (l *LimitedByteWriter) WriteByte(c byte) error { | ||
29 | if l.N <= 0 { | ||
30 | return ErrLimit | ||
31 | } | ||
32 | if err := l.BW.WriteByte(c); err != nil { | ||
33 | return err | ||
34 | } | ||
35 | l.N-- | ||
36 | return nil | ||
37 | } | ||