Skip to content

Commit f59c58d

Browse files
committed
Added new stream type which will request its size from its stream. This triggers full decompression, currently, but allows work to be delayed even further.If people want a stream, they usually read it anyway. Then it doesn't matter which attriubute they query first
1 parent 9a3fbb7 commit f59c58d

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

base.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,23 @@ def read(self, size=-1):
135135
@property
136136
def stream(self):
137137
return self[3]
138+
139+
#} END stream reader interface
140+
141+
142+
class ODeltaStream(OStream):
143+
"""Uses size info of its stream, delaying reads"""
144+
145+
def __new__(cls, sha, type, size, stream, *args, **kwargs):
146+
"""Helps with the initialization of subclasses"""
147+
return tuple.__new__(cls, (sha, type, size, stream))
148+
149+
#{ Stream Reader Interface
150+
151+
@property
152+
def size(self):
153+
return self[3].size
154+
138155
#} END stream reader interface
139156

140157

pack.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
OStream,
3535
OPackInfo,
3636
OPackStream,
37+
ODeltaStream,
3738
ODeltaPackInfo,
3839
ODeltaPackStream,
3940
)
@@ -584,14 +585,9 @@ def _object(self, sha, as_stream, index=-1):
584585
# To prevent it from applying the deltas when querying the size,
585586
# we extract it from the delta stream ourselves
586587
streams = self.collect_streams_at_offset(offset)
587-
buf = streams[0].read(512)
588-
offset, src_size = msb_size(buf)
589-
offset, target_size = msb_size(buf, offset)
590-
591-
streams[0].stream.seek(0) # assure it can be read by the delta reader
592588
dstream = DeltaApplyReader.new(streams)
593589

594-
return OStream(sha, dstream.type, target_size, dstream)
590+
return ODeltaStream(sha, dstream.type, None, dstream)
595591
else:
596592
if type_id not in delta_types:
597593
return OInfo(sha, type_id_to_type_map[type_id], uncomp_size)

0 commit comments

Comments
 (0)