Merge pull request #363 from hainesr/fix-dir-glob
Fix Zip::FileSystem::ZipFsDir#glob
This commit is contained in:
commit
6ea4a7171f
|
@ -573,6 +573,10 @@ module Zip
|
||||||
@zipFile.get_output_stream(expand_to_entry(fileName), permissionInt, &aProc)
|
@zipFile.get_output_stream(expand_to_entry(fileName), permissionInt, &aProc)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def glob(pattern, *flags, &block)
|
||||||
|
@zipFile.glob(expand_to_entry(pattern), *flags, &block)
|
||||||
|
end
|
||||||
|
|
||||||
def read(fileName)
|
def read(fileName)
|
||||||
@zipFile.read(expand_to_entry(fileName))
|
@zipFile.read(expand_to_entry(fileName))
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,6 +3,7 @@ require 'zip/filesystem'
|
||||||
|
|
||||||
class ZipFsDirectoryTest < MiniTest::Test
|
class ZipFsDirectoryTest < MiniTest::Test
|
||||||
TEST_ZIP = 'test/data/generated/zipWithDirs_copy.zip'
|
TEST_ZIP = 'test/data/generated/zipWithDirs_copy.zip'
|
||||||
|
GLOB_TEST_ZIP = 'test/data/globTest.zip'
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
FileUtils.cp('test/data/zipWithDirs.zip', TEST_ZIP)
|
FileUtils.cp('test/data/zipWithDirs.zip', TEST_ZIP)
|
||||||
|
@ -93,11 +94,28 @@ class ZipFsDirectoryTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Globbing not supported yet
|
def test_glob
|
||||||
# def test_glob
|
globbed_files = [
|
||||||
# # test alias []-operator too
|
'globTest/foo/bar/baz/foo.txt',
|
||||||
# fail "implement test"
|
'globTest/foo.txt',
|
||||||
# end
|
'globTest/food.txt'
|
||||||
|
]
|
||||||
|
|
||||||
|
::Zip::File.open(GLOB_TEST_ZIP) do |zf|
|
||||||
|
zf.dir.glob('**/*.txt') do |f|
|
||||||
|
assert globbed_files.include?(f.name)
|
||||||
|
end
|
||||||
|
|
||||||
|
zf.dir.glob('globTest/foo/**/*.txt') do |f|
|
||||||
|
assert_equal globbed_files[0], f.name
|
||||||
|
end
|
||||||
|
|
||||||
|
zf.dir.chdir('globTest/foo')
|
||||||
|
zf.dir.glob('**/*.txt') do |f|
|
||||||
|
assert_equal globbed_files[0], f.name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_open_new
|
def test_open_new
|
||||||
::Zip::File.open(TEST_ZIP) do |zf|
|
::Zip::File.open(TEST_ZIP) do |zf|
|
||||||
|
|
Loading…
Reference in New Issue