Now runs with -w switch without warnings
This commit is contained in:
parent
759b264807
commit
24beca5136
7
NEWS
7
NEWS
|
@ -1,3 +1,10 @@
|
||||||
|
= Version 0.4.0 =
|
||||||
|
|
||||||
|
ZipFile is now mutable and provides a more convenient way of modifying
|
||||||
|
zip archives than ZipOutputStream.
|
||||||
|
|
||||||
|
Runs without warnings with -w switch.
|
||||||
|
|
||||||
= Version 0.3.1 =
|
= Version 0.3.1 =
|
||||||
|
|
||||||
Rudimentary support for writing zip archives.
|
Rudimentary support for writing zip archives.
|
||||||
|
|
15
TODO
15
TODO
|
@ -3,9 +3,24 @@ write ZipFile.
|
||||||
unit test writeFile (onExistsProc)
|
unit test writeFile (onExistsProc)
|
||||||
unit test rename onExistsProc
|
unit test rename onExistsProc
|
||||||
unit test yield on ZipFile::getInputStream
|
unit test yield on ZipFile::getInputStream
|
||||||
|
unit test adding directories (and implement)
|
||||||
|
unit test adding directories recursively (and implement)
|
||||||
|
unit test ZipFile.checkIntegrity method (and implement)
|
||||||
|
unit test and implement recursive extract (and implement)
|
||||||
|
|
||||||
|
performance improve method
|
||||||
|
ZipStreamableZipEntry.writeToZipOutputStream by not
|
||||||
|
decompressing/compressing the data.
|
||||||
|
|
||||||
release 0.4.0
|
release 0.4.0
|
||||||
|
|
||||||
|
implement small gui app on top, to exercise library and to discover
|
||||||
|
what features should be added to rubyzip. Use tk.
|
||||||
|
|
||||||
|
implement setting the date correctly in ZipEntry with now as default
|
||||||
|
|
||||||
|
release 0.4.1 with small gui demo app and fixes
|
||||||
|
|
||||||
Refactor ZipFileTest to reduce duplicated code, divide into different
|
Refactor ZipFileTest to reduce duplicated code, divide into different
|
||||||
test classes if different fixtures are required and use setup/teardown
|
test classes if different fixtures are required and use setup/teardown
|
||||||
some more.
|
some more.
|
||||||
|
|
39
zip.rb
39
zip.rb
|
@ -33,7 +33,7 @@ module Zip
|
||||||
end
|
end
|
||||||
|
|
||||||
def gets(aSepString=$/)
|
def gets(aSepString=$/)
|
||||||
@outputBuffer="" unless @outputBuffer
|
@outputBuffer ||= ""
|
||||||
return read if aSepString == nil
|
return read if aSepString == nil
|
||||||
aSepString="#{$/}#{$/}" if aSepString == ""
|
aSepString="#{$/}#{$/}" if aSepString == ""
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@ module Zip
|
||||||
end
|
end
|
||||||
|
|
||||||
def flush
|
def flush
|
||||||
|
@outputBuffer ||= ""
|
||||||
retVal=@outputBuffer
|
retVal=@outputBuffer
|
||||||
@outputBuffer=""
|
@outputBuffer=""
|
||||||
return retVal
|
return retVal
|
||||||
|
@ -117,6 +118,7 @@ module Zip
|
||||||
@archiveIO = File.open(filename, "rb")
|
@archiveIO = File.open(filename, "rb")
|
||||||
@archiveIO.seek(offset, IO::SEEK_SET)
|
@archiveIO.seek(offset, IO::SEEK_SET)
|
||||||
@decompressor = NullDecompressor.instance
|
@decompressor = NullDecompressor.instance
|
||||||
|
@currentEntry = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def close
|
def close
|
||||||
|
@ -177,6 +179,7 @@ module Zip
|
||||||
super
|
super
|
||||||
@zlibInflater = Zlib::Inflate.new(-Zlib::Inflate::MAX_WBITS)
|
@zlibInflater = Zlib::Inflate.new(-Zlib::Inflate::MAX_WBITS)
|
||||||
@outputBuffer=""
|
@outputBuffer=""
|
||||||
|
@hasReturnedEmptyString = false
|
||||||
end
|
end
|
||||||
|
|
||||||
def read(numberOfBytes = nil)
|
def read(numberOfBytes = nil)
|
||||||
|
@ -265,6 +268,7 @@ module Zip
|
||||||
|
|
||||||
def initialize(name = "", comment = "", extra = "", compressedSize = 0,
|
def initialize(name = "", comment = "", extra = "", compressedSize = 0,
|
||||||
crc = 0, compressionMethod = ZipEntry::DEFLATED, size = 0)
|
crc = 0, compressionMethod = ZipEntry::DEFLATED, size = 0)
|
||||||
|
@localHeaderOffset = 0
|
||||||
@comment, @compressedSize, @crc, @extra, @compressionMethod,
|
@comment, @compressedSize, @crc, @extra, @compressionMethod,
|
||||||
@name, @size, @isDirectory = comment, compressedSize, crc,
|
@name, @size, @isDirectory = comment, compressedSize, crc,
|
||||||
extra, compressionMethod, name, size
|
extra, compressionMethod, name, size
|
||||||
|
@ -352,11 +356,11 @@ module Zip
|
||||||
|
|
||||||
io <<
|
io <<
|
||||||
[LOCAL_ENTRY_SIGNATURE ,
|
[LOCAL_ENTRY_SIGNATURE ,
|
||||||
@version ,
|
0 , # @version ,
|
||||||
@gpFlags ,
|
0 , # @gpFlags ,
|
||||||
@compressionMethod ,
|
@compressionMethod ,
|
||||||
@lastModTime ,
|
0 , # @lastModTime ,
|
||||||
@lastModDate ,
|
0 , # @lastModDate ,
|
||||||
@crc ,
|
@crc ,
|
||||||
@compressedSize ,
|
@compressedSize ,
|
||||||
@size ,
|
@size ,
|
||||||
|
@ -420,12 +424,12 @@ module Zip
|
||||||
def writeCDirEntry(io)
|
def writeCDirEntry(io)
|
||||||
io <<
|
io <<
|
||||||
[CENTRAL_DIRECTORY_ENTRY_SIGNATURE,
|
[CENTRAL_DIRECTORY_ENTRY_SIGNATURE,
|
||||||
@version ,
|
0 , # @version ,
|
||||||
@versionNeededToExtract ,
|
0 , # @versionNeededToExtract ,
|
||||||
@gpFlags ,
|
0 , # @gpFlags ,
|
||||||
@compressionMethod ,
|
@compressionMethod ,
|
||||||
@lastModTime ,
|
0 , # @lastModTime ,
|
||||||
@lastModDate ,
|
0 , # @lastModDate ,
|
||||||
@crc ,
|
@crc ,
|
||||||
@compressedSize ,
|
@compressedSize ,
|
||||||
@size ,
|
@size ,
|
||||||
|
@ -433,8 +437,8 @@ module Zip
|
||||||
@extra ? @extra.length : 0 ,
|
@extra ? @extra.length : 0 ,
|
||||||
@comment ? comment.length : 0 ,
|
@comment ? comment.length : 0 ,
|
||||||
0 , # disk number start
|
0 , # disk number start
|
||||||
@internalFileAttributes ,
|
0 , # @internalFileAttributes ,
|
||||||
@externalFileAttributes ,
|
0 , # @externalFileAttributes ,
|
||||||
@localHeaderOffset ,
|
@localHeaderOffset ,
|
||||||
@name ,
|
@name ,
|
||||||
@extra ,
|
@extra ,
|
||||||
|
@ -483,6 +487,9 @@ module Zip
|
||||||
@outputStream = File.new(@fileName, "wb")
|
@outputStream = File.new(@fileName, "wb")
|
||||||
@entries = []
|
@entries = []
|
||||||
@compressor = NullCompressor.instance
|
@compressor = NullCompressor.instance
|
||||||
|
@closed = false
|
||||||
|
@currentEntry = nil
|
||||||
|
@comment = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def ZipOutputStream.open(fileName)
|
def ZipOutputStream.open(fileName)
|
||||||
|
@ -707,7 +714,7 @@ module Zip
|
||||||
end
|
end
|
||||||
|
|
||||||
def each(&proc)
|
def each(&proc)
|
||||||
@entries.each &proc
|
@entries.each(&proc)
|
||||||
end
|
end
|
||||||
|
|
||||||
def ZipCentralDirectory.readFromStream(io)
|
def ZipCentralDirectory.readFromStream(io)
|
||||||
|
@ -734,6 +741,7 @@ module Zip
|
||||||
|
|
||||||
def initialize(name)
|
def initialize(name)
|
||||||
@name=name
|
@name=name
|
||||||
|
@comment = ""
|
||||||
File.open(name) {
|
File.open(name) {
|
||||||
|file|
|
|file|
|
||||||
readFromStream(file)
|
readFromStream(file)
|
||||||
|
@ -742,7 +750,7 @@ module Zip
|
||||||
|
|
||||||
def BasicZipFile.foreach(aZipFileName, &block)
|
def BasicZipFile.foreach(aZipFileName, &block)
|
||||||
zipFile = BasicZipFile.new(aZipFileName)
|
zipFile = BasicZipFile.new(aZipFileName)
|
||||||
zipFile.each &block
|
zipFile.each(&block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def getInputStream(entry)
|
def getInputStream(entry)
|
||||||
|
@ -772,6 +780,7 @@ module Zip
|
||||||
|
|
||||||
def initialize(fileName, create = nil)
|
def initialize(fileName, create = nil)
|
||||||
@name = fileName
|
@name = fileName
|
||||||
|
@comment = ""
|
||||||
if (File.exists?(fileName))
|
if (File.exists?(fileName))
|
||||||
super(fileName)
|
super(fileName)
|
||||||
fixEntries
|
fixEntries
|
||||||
|
@ -825,7 +834,7 @@ module Zip
|
||||||
end
|
end
|
||||||
|
|
||||||
def getInputStream(entry, &aProc)
|
def getInputStream(entry, &aProc)
|
||||||
getEntry(entry).getInputStream &aProc
|
getEntry(entry).getInputStream(&aProc)
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract(entry, destPath, onExistsProc = proc { false })
|
def extract(entry, destPath, onExistsProc = proc { false })
|
||||||
|
|
15
ziptest.rb
15
ziptest.rb
|
@ -6,7 +6,6 @@ require 'zip'
|
||||||
|
|
||||||
include Zip
|
include Zip
|
||||||
|
|
||||||
|
|
||||||
class AbstractInputStreamTest < RUNIT::TestCase
|
class AbstractInputStreamTest < RUNIT::TestCase
|
||||||
# AbstractInputStream subclass that provides a read method
|
# AbstractInputStream subclass that provides a read method
|
||||||
|
|
||||||
|
@ -141,7 +140,7 @@ module IOizeString
|
||||||
attr_reader :tell
|
attr_reader :tell
|
||||||
|
|
||||||
def read(count = nil)
|
def read(count = nil)
|
||||||
@tell = 0 unless @tell
|
@tell ||= 0
|
||||||
count = size unless count
|
count = size unless count
|
||||||
retVal = slice(@tell, count)
|
retVal = slice(@tell, count)
|
||||||
@tell += count
|
@tell += count
|
||||||
|
@ -149,6 +148,7 @@ module IOizeString
|
||||||
end
|
end
|
||||||
|
|
||||||
def seek(index, offset)
|
def seek(index, offset)
|
||||||
|
@tell ||= 0
|
||||||
case offset
|
case offset
|
||||||
when IO::SEEK_END
|
when IO::SEEK_END
|
||||||
newPos = size + index
|
newPos = size + index
|
||||||
|
@ -165,6 +165,10 @@ module IOizeString
|
||||||
@tell=newPos
|
@tell=newPos
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reset
|
||||||
|
@tell = 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ZipLocalEntryTest < RUNIT::TestCase
|
class ZipLocalEntryTest < RUNIT::TestCase
|
||||||
|
@ -197,7 +201,7 @@ class ZipLocalEntryTest < RUNIT::TestCase
|
||||||
def test_readLocalEntryFromTruncatedZipFile
|
def test_readLocalEntryFromTruncatedZipFile
|
||||||
zipFragment=""
|
zipFragment=""
|
||||||
File.open(TestZipFile::TEST_ZIP2.zipName) { |f| zipFragment = f.read(12) } # local header is at least 30 bytes
|
File.open(TestZipFile::TEST_ZIP2.zipName) { |f| zipFragment = f.read(12) } # local header is at least 30 bytes
|
||||||
zipFragment.extend(IOizeString)
|
zipFragment.extend(IOizeString).reset
|
||||||
entry = ZipEntry.new
|
entry = ZipEntry.new
|
||||||
entry.readLocalEntry(zipFragment)
|
entry.readLocalEntry(zipFragment)
|
||||||
fail "ZipError expected"
|
fail "ZipError expected"
|
||||||
|
@ -1080,12 +1084,12 @@ class ZipFileTest < RUNIT::TestCase
|
||||||
|
|
||||||
def test_extractNonEntry
|
def test_extractNonEntry
|
||||||
zf = ZipFile.new(TEST_ZIP.zipName)
|
zf = ZipFile.new(TEST_ZIP.zipName)
|
||||||
assert_exception(ZipError) { zf.extract("nonExistingEntry") }
|
assert_exception(ZipError) { zf.extract("nonExistingEntry", "nonExistingEntry") }
|
||||||
ensure
|
ensure
|
||||||
zf.close if zf
|
zf.close if zf
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_extractNonEntry
|
def test_extractNonEntry2
|
||||||
outFile = "outfile"
|
outFile = "outfile"
|
||||||
assert_exception(ZipError) {
|
assert_exception(ZipError) {
|
||||||
zf = ZipFile.new(TEST_ZIP.zipName)
|
zf = ZipFile.new(TEST_ZIP.zipName)
|
||||||
|
@ -1286,7 +1290,6 @@ end
|
||||||
TestZipFile::createTestZips(ARGV.index("recreate") != nil)
|
TestZipFile::createTestZips(ARGV.index("recreate") != nil)
|
||||||
TestFiles::createTestFiles(ARGV.index("recreate") != nil)
|
TestFiles::createTestFiles(ARGV.index("recreate") != nil)
|
||||||
|
|
||||||
|
|
||||||
# Copyright (C) 2002 Thomas Sondergaard
|
# Copyright (C) 2002 Thomas Sondergaard
|
||||||
# rubyzip is free software; you can redistribute it and/or
|
# rubyzip is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the ruby license.
|
# modify it under the terms of the ruby license.
|
||||||
|
|
Loading…
Reference in New Issue