OLD | NEW |
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 |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 // | 202 // |
203 // UnreadRune causes the next call to ReadRune to return the same rune | 203 // UnreadRune causes the next call to ReadRune to return the same rune |
204 // as the previous call to ReadRune. | 204 // as the previous call to ReadRune. |
205 // It may be an error to call UnreadRune twice without an intervening | 205 // It may be an error to call UnreadRune twice without an intervening |
206 // call to ReadRune. | 206 // call to ReadRune. |
207 type RuneScanner interface { | 207 type RuneScanner interface { |
208 RuneReader | 208 RuneReader |
209 UnreadRune() os.Error | 209 UnreadRune() os.Error |
210 } | 210 } |
211 | 211 |
| 212 // stringWriter is the interface that wraps the WriteString method. |
| 213 type stringWriter interface { |
| 214 WriteString(s string) (n int, err os.Error) |
| 215 } |
| 216 |
212 // WriteString writes the contents of the string s to w, which accepts an array
of bytes. | 217 // WriteString writes the contents of the string s to w, which accepts an array
of bytes. |
213 func WriteString(w Writer, s string) (n int, err os.Error) { | 218 func WriteString(w Writer, s string) (n int, err os.Error) { |
| 219 if sw, ok := w.(stringWriter); ok { |
| 220 return sw.WriteString(s) |
| 221 } |
214 return w.Write([]byte(s)) | 222 return w.Write([]byte(s)) |
215 } | 223 } |
216 | 224 |
217 // ReadAtLeast reads from r into buf until it has read at least min bytes. | 225 // ReadAtLeast reads from r into buf until it has read at least min bytes. |
218 // It returns the number of bytes copied and an error if fewer bytes were read. | 226 // It returns the number of bytes copied and an error if fewer bytes were read. |
219 // The error is os.EOF only if no bytes were read. | 227 // The error is os.EOF only if no bytes were read. |
220 // If an EOF happens after reading fewer than min bytes, | 228 // If an EOF happens after reading fewer than min bytes, |
221 // ReadAtLeast returns ErrUnexpectedEOF. | 229 // ReadAtLeast returns ErrUnexpectedEOF. |
222 // If min is greater than the length of buf, ReadAtLeast returns ErrShortBuffer. | 230 // If min is greater than the length of buf, ReadAtLeast returns ErrShortBuffer. |
223 func ReadAtLeast(r Reader, buf []byte, min int) (n int, err os.Error) { | 231 func ReadAtLeast(r Reader, buf []byte, min int) (n int, err os.Error) { |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 } | 430 } |
423 off += s.base | 431 off += s.base |
424 if max := s.limit - off; int64(len(p)) > max { | 432 if max := s.limit - off; int64(len(p)) > max { |
425 p = p[0:max] | 433 p = p[0:max] |
426 } | 434 } |
427 return s.r.ReadAt(p, off) | 435 return s.r.ReadAt(p, off) |
428 } | 436 } |
429 | 437 |
430 // Size returns the size of the section in bytes. | 438 // Size returns the size of the section in bytes. |
431 func (s *SectionReader) Size() int64 { return s.limit - s.base } | 439 func (s *SectionReader) Size() int64 { return s.limit - s.base } |
OLD | NEW |