Make remote IOs rewindable

This is required for active storage to work
This commit is contained in:
Stanko K.R.
2026-02-02 13:52:14 +01:00
parent 8be26a283e
commit edb676cd2c
2 changed files with 11 additions and 6 deletions
+2 -4
View File
@@ -9,12 +9,10 @@ class ZipFile::Reader
raise ArgumentError, "File not found in zip: #{file_path}" unless entry
raise ArgumentError, "Cannot read directory entry: #{file_path}" if entry.filename.end_with?("/")
extractor = entry.extractor_from(@io)
if block_given?
yield ZipFile::Reader::ExtractorIO.new(extractor)
yield ZipFile::Reader::ExtractorIO.new(entry, @io)
else
extractor.extract
entry.extractor_from(@io).extract
end
end
+9 -2
View File
@@ -1,6 +1,8 @@
class ZipFile::Reader::ExtractorIO
def initialize(extractor)
@extractor = extractor
def initialize(entry, io)
@entry = entry
@io = io
@extractor = @entry.extractor_from(@io)
end
def read(length = nil, buffer = nil)
@@ -20,4 +22,9 @@ class ZipFile::Reader::ExtractorIO
def eof?
@extractor.eof?
end
def rewind
@extractor = @entry.extractor_from(@io)
0
end
end