Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Package io provides basic interfaces to I/O primitives. | 5 // Package io provides basic interfaces to I/O primitives. |
6 // Its primary job is to wrap existing implementations of such primitives, | 6 // Its primary job is to wrap existing implementations of such primitives, |
7 // such as those in package os, into shared public interfaces that | 7 // such as those in package os, into shared public interfaces that |
8 // abstract the functionality, plus some other related primitives. | 8 // abstract the functionality, plus some other related primitives. |
9 package io | 9 package io |
10 | 10 |
11 import "os" | 11 import "os" |
12 | 12 |
13 // Error represents an unexpected I/O behavior. | 13 // Error represents an unexpected I/O behavior. |
14 type Error struct { | 14 type Error struct { |
15 » os.Error | 15 » ErrorString string |
rsc
2011/06/21 19:03:48
Instead of this, which I fear will lead to more co
gri1
2011/06/21 19:12:30
Done.
| |
16 } | 16 } |
17 | |
18 func (err *Error) String() string { return err.ErrorString } | |
17 | 19 |
18 // ErrShortWrite means that a write accepted fewer bytes than requested | 20 // ErrShortWrite means that a write accepted fewer bytes than requested |
19 // but failed to return an explicit error. | 21 // but failed to return an explicit error. |
20 var ErrShortWrite os.Error = &Error{os.NewError("short write")} | 22 var ErrShortWrite os.Error = &Error{"short write"} |
21 | 23 |
22 // ErrShortBuffer means that a read required a longer buffer than was provided. | 24 // ErrShortBuffer means that a read required a longer buffer than was provided. |
23 var ErrShortBuffer os.Error = &Error{os.NewError("short buffer")} | 25 var ErrShortBuffer os.Error = &Error{"short buffer"} |
24 | 26 |
25 // ErrUnexpectedEOF means that os.EOF was encountered in the | 27 // ErrUnexpectedEOF means that os.EOF was encountered in the |
26 // middle of reading a fixed-size block or data structure. | 28 // middle of reading a fixed-size block or data structure. |
27 var ErrUnexpectedEOF os.Error = &Error{os.NewError("unexpected EOF")} | 29 var ErrUnexpectedEOF os.Error = &Error{"unexpected EOF"} |
28 | 30 |
29 // Reader is the interface that wraps the basic Read method. | 31 // Reader is the interface that wraps the basic Read method. |
30 // | 32 // |
31 // Read reads up to len(p) bytes into p. It returns the number of bytes | 33 // Read reads up to len(p) bytes into p. It returns the number of bytes |
32 // read (0 <= n <= len(p)) and any error encountered. | 34 // read (0 <= n <= len(p)) and any error encountered. |
33 // Even if Read returns n < len(p), | 35 // Even if Read returns n < len(p), |
34 // it may use all of p as scratch space during the call. | 36 // it may use all of p as scratch space during the call. |
35 // If some data is available but not len(p) bytes, Read conventionally | 37 // If some data is available but not len(p) bytes, Read conventionally |
36 // returns what is available rather than block waiting for more. | 38 // returns what is available rather than block waiting for more. |
37 // | 39 // |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
401 } | 403 } |
402 off += s.base | 404 off += s.base |
403 if max := s.limit - off; int64(len(p)) > max { | 405 if max := s.limit - off; int64(len(p)) > max { |
404 p = p[0:max] | 406 p = p[0:max] |
405 } | 407 } |
406 return s.r.ReadAt(p, off) | 408 return s.r.ReadAt(p, off) |
407 } | 409 } |
408 | 410 |
409 // Size returns the size of the section in bytes. | 411 // Size returns the size of the section in bytes. |
410 func (s *SectionReader) Size() int64 { return s.limit - s.base } | 412 func (s *SectionReader) Size() int64 { return s.limit - s.base } |
LEFT | RIGHT |