Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
77b2d63b
Commit
77b2d63b
authored
Dec 01, 2007
by
Lars Gustäbel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #1531: Read fileobj from the current offset, do not seek to
the start. (will backport to 2.5)
parent
3e76d934
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
1 deletion
+37
-1
Lib/tarfile.py
Lib/tarfile.py
+2
-1
Lib/test/test_tarfile.py
Lib/test/test_tarfile.py
+32
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/tarfile.py
View file @
77b2d63b
...
...
@@ -1558,7 +1558,8 @@ class TarFile(object):
self.closed = False
self.members = [] # list of members as TarInfo objects
self._loaded = False # flag if all members have been read
self.offset = 0L # current position in the archive file
self.offset = self.fileobj.tell()
# current position in the archive file
self.inodes = {} # dictionary caching the inodes of
# archive members already added
...
...
Lib/test/test_tarfile.py
View file @
77b2d63b
...
...
@@ -160,6 +160,38 @@ class MiscReadTest(ReadTest):
tar
=
tarfile
.
open
(
fileobj
=
fobj
,
mode
=
self
.
mode
)
self
.
assertEqual
(
tar
.
name
,
None
)
def
test_fileobj_with_offset
(
self
):
# Skip the first member and store values from the second member
# of the testtar.
tar
=
tarfile
.
open
(
self
.
tarname
,
mode
=
self
.
mode
)
tar
.
next
()
t
=
tar
.
next
()
name
=
t
.
name
offset
=
t
.
offset
data
=
tar
.
extractfile
(
t
).
read
()
tar
.
close
()
# Open the testtar and seek to the offset of the second member.
if
self
.
mode
.
endswith
(
":gz"
):
_open
=
gzip
.
GzipFile
elif
self
.
mode
.
endswith
(
":bz2"
):
_open
=
bz2
.
BZ2File
else
:
_open
=
open
fobj
=
_open
(
self
.
tarname
,
"rb"
)
fobj
.
seek
(
offset
)
# Test if the tarfile starts with the second member.
tar
=
tar
.
open
(
self
.
tarname
,
mode
=
"r:"
,
fileobj
=
fobj
)
t
=
tar
.
next
()
self
.
assertEqual
(
t
.
name
,
name
)
# Read to the end of fileobj and test if seeking back to the
# beginning works.
tar
.
getmembers
()
self
.
assertEqual
(
tar
.
extractfile
(
t
).
read
(),
data
,
"seek back did not work"
)
tar
.
close
()
def
test_fail_comp
(
self
):
# For Gzip and Bz2 Tests: fail with a ReadError on an uncompressed file.
if
self
.
mode
==
"r:"
:
...
...
Misc/NEWS
View file @
77b2d63b
...
...
@@ -304,6 +304,9 @@ Core and builtins
Library
-------
-
Issue
#
1531
:
tarfile
.
py
:
Read
fileobj
from
the
current
offset
,
do
not
seek
to
the
start
.
-
Issue
#
1534
:
Added
a
dictionary
sys
.
float_info
with
information
about
the
internal
floating
point
type
to
the
sys
module
.
...
...
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