-
-
Notifications
You must be signed in to change notification settings - Fork 34.7k
gh-90533: Implement BytesIO.peek() #30808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b833b83
50a2cfb
eaa7672
00457ae
882579d
c1eed72
afc200c
79ab9a4
b493914
2a1c85c
d398717
26d1e81
9a19ff9
9300ade
d214089
d6691b8
3e51adb
3661b65
cd40d77
04372bd
6b9ae8c
f7406f6
d9528e2
bc8134b
b6ffca8
5fe5645
4126a64
1ea40c2
77e04d6
4d2f2dd
c16bebf
08bd7da
6174fca
b8b8cf4
7ac914e
abbd8f0
07d9e4d
3d57f45
023ad25
203749b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -996,6 +996,13 @@ def tell(self): | |
| raise ValueError("tell on closed file") | ||
| return self._pos | ||
|
|
||
| def peek(self, size=0): | ||
| if self.closed: | ||
| raise ValueError("peek on closed file") | ||
| if size < 1: | ||
|
cmaloney marked this conversation as resolved.
|
||
| return self._buffer[self._pos:self._pos + DEFAULT_BUFFER_SIZE] | ||
| return self._buffer[self._pos:self._pos + min(size, DEFAULT_BUFFER_SIZE)] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not think For But for It is reasonable to use DEFAULT_BUFFER_SIZE by default, when size <= 0.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: this detail can be changed later, it should not be a blocker. |
||
|
|
||
| def truncate(self, pos=None): | ||
| if self.closed: | ||
| raise ValueError("truncate on closed file") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add :meth:`io.BytesIO.peek`. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.