File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ class Tar extends Archive
24
24
protected $ closed = true ;
25
25
protected $ writeaccess = false ;
26
26
protected $ position = 0 ;
27
+ protected $ contentUntil = 0 ;
27
28
protected $ skipUntil = 0 ;
28
29
29
30
/**
@@ -121,6 +122,7 @@ public function yieldContents()
121
122
continue ;
122
123
}
123
124
125
+ $ this ->contentUntil = $ this ->position + $ header ['size ' ];
124
126
$ this ->skipUntil = $ this ->position + ceil ($ header ['size ' ] / 512 ) * 512 ;
125
127
126
128
yield $ this ->header2fileinfo ($ header );
@@ -134,9 +136,22 @@ public function yieldContents()
134
136
$ this ->close ();
135
137
}
136
138
139
+ /**
140
+ * Reads content of a current archive entry.
141
+ *
142
+ * Works only when iterating trough the archive using the generator returned
143
+ * by the yieldContents().
144
+ *
145
+ * @param int $length maximum number of bytes to read
146
+ *
147
+ * @return string
148
+ */
137
149
public function readCurrentEntry ($ length = PHP_INT_MAX )
138
150
{
139
- $ length = min ($ length , $ this ->skipUntil - $ this ->position );
151
+ $ length = (int ) min ($ length , $ this ->contentUntil - $ this ->position );
152
+ if ($ length === 0 ) {
153
+ return '' ;
154
+ }
140
155
return $ this ->readbytes ($ length );
141
156
}
142
157
@@ -790,3 +805,4 @@ static public function numberEncode($value, $length)
790
805
return $ encoded ;
791
806
}
792
807
}
808
+
You can’t perform that action at this time.
0 commit comments