Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
24a78a02
Commit
24a78a02
authored
Dec 07, 2010
by
Roger Peppe
Committed by
Russ Cox
Dec 07, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bufio: make Reader.Read implement io.Reader semantics
R=rsc CC=golang-dev
https://golang.org/cl/3395042
parent
cf6c2121
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
33 deletions
+34
-33
src/pkg/bufio/bufio.go
src/pkg/bufio/bufio.go
+34
-33
No files found.
src/pkg/bufio/bufio.go
View file @
24a78a02
...
@@ -128,43 +128,44 @@ func (b *Reader) Peek(n int) ([]byte, os.Error) {
...
@@ -128,43 +128,44 @@ func (b *Reader) Peek(n int) ([]byte, os.Error) {
// Read reads data into p.
// Read reads data into p.
// It returns the number of bytes read into p.
// It returns the number of bytes read into p.
// If nn < len(p), also returns an error explaining
// It calls Read at most once on the underlying Reader,
// why the read is short. At EOF, the count will be
// hence n may be less than len(p).
// zero and err will be os.EOF.
// At EOF, the count will be zero and err will be os.EOF.
func
(
b
*
Reader
)
Read
(
p
[]
byte
)
(
nn
int
,
err
os
.
Error
)
{
func
(
b
*
Reader
)
Read
(
p
[]
byte
)
(
n
int
,
err
os
.
Error
)
{
nn
=
0
n
=
len
(
p
)
for
len
(
p
)
>
0
{
if
n
==
0
{
n
:=
len
(
p
)
return
0
,
b
.
err
if
b
.
w
==
b
.
r
{
}
if
b
.
err
!=
nil
{
if
b
.
w
==
b
.
r
{
return
nn
,
b
.
err
if
b
.
err
!=
nil
{
}
return
0
,
b
.
err
if
len
(
p
)
>=
len
(
b
.
buf
)
{
}
// Large read, empty buffer.
if
len
(
p
)
>=
len
(
b
.
buf
)
{
// Read directly into p to avoid copy.
// Large read, empty buffer.
n
,
b
.
err
=
b
.
rd
.
Read
(
p
)
// Read directly into p to avoid copy.
if
n
>
0
{
n
,
b
.
err
=
b
.
rd
.
Read
(
p
)
b
.
lastByte
=
int
(
p
[
n
-
1
])
if
n
>
0
{
b
.
lastRuneSize
=
-
1
b
.
lastByte
=
int
(
p
[
n
-
1
])
}
b
.
lastRuneSize
=
-
1
p
=
p
[
n
:
]
nn
+=
n
continue
}
}
b
.
fill
()
p
=
p
[
n
:
]
continue
return
n
,
b
.
err
}
}
if
n
>
b
.
w
-
b
.
r
{
b
.
fill
()
n
=
b
.
w
-
b
.
r
if
b
.
w
==
b
.
r
{
return
0
,
b
.
err
}
}
copy
(
p
[
0
:
n
],
b
.
buf
[
b
.
r
:
])
p
=
p
[
n
:
]
b
.
r
+=
n
b
.
lastByte
=
int
(
b
.
buf
[
b
.
r
-
1
])
b
.
lastRuneSize
=
-
1
nn
+=
n
}
}
return
nn
,
nil
if
n
>
b
.
w
-
b
.
r
{
n
=
b
.
w
-
b
.
r
}
copy
(
p
[
0
:
n
],
b
.
buf
[
b
.
r
:
])
p
=
p
[
n
:
]
b
.
r
+=
n
b
.
lastByte
=
int
(
b
.
buf
[
b
.
r
-
1
])
b
.
lastRuneSize
=
-
1
return
n
,
nil
}
}
// ReadByte reads and returns a single byte.
// ReadByte reads and returns a single byte.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment