summaryrefslogtreecommitdiff
path: root/lib/rubygems/package/tar_writer.rb
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-06-09 21:38:59 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-06-09 21:38:59 +0000
commit31c94ffeb5f09d09ac2c86fc9e6614e38251a43d (patch)
tree10e44506238c7af3d7c9d822111996731726e38d /lib/rubygems/package/tar_writer.rb
parenta6afbaeb3be396c0fdea3b9077d9256c59edcfca (diff)
Update to RubyGems 1.3.4 r2223
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/package/tar_writer.rb')
-rw-r--r--lib/rubygems/package/tar_writer.rb70
1 files changed, 65 insertions, 5 deletions
diff --git a/lib/rubygems/package/tar_writer.rb b/lib/rubygems/package/tar_writer.rb
index 04a15c7779..6f11529302 100644
--- a/lib/rubygems/package/tar_writer.rb
+++ b/lib/rubygems/package/tar_writer.rb
@@ -3,15 +3,30 @@
# See LICENSE.txt for additional licensing information.
#--
-require 'rubygems/package'
+##
+# Allows writing of tar files
class Gem::Package::TarWriter
class FileOverflow < StandardError; end
+ ##
+ # IO wrapper that allows writing a limited amount of data
+
class BoundedStream
- attr_reader :limit, :written
+ ##
+ # Maximum number of bytes that can be written
+
+ attr_reader :limit
+
+ ##
+ # Number of bytes written
+
+ attr_reader :written
+
+ ##
+ # Wraps +io+ and allows up to +limit+ bytes to be written
def initialize(io, limit)
@io = io
@@ -19,6 +34,10 @@ class Gem::Package::TarWriter
@written = 0
end
+ ##
+ # Writes +data+ onto the IO, raising a FileOverflow exception if the
+ # number of bytes will be more than #limit
+
def write(data)
if data.size + @written > @limit
raise FileOverflow, "You tried to feed more data than fits in the file."
@@ -30,18 +49,30 @@ class Gem::Package::TarWriter
end
+ ##
+ # IO wrapper that provides only #write
+
class RestrictedStream
+ ##
+ # Creates a new RestrictedStream wrapping +io+
+
def initialize(io)
@io = io
end
+ ##
+ # Writes +data+ onto the IO
+
def write(data)
@io.write data
end
end
+ ##
+ # Creates a new TarWriter, yielding it if a block is given
+
def self.new(io)
writer = super
@@ -56,12 +87,19 @@ class Gem::Package::TarWriter
nil
end
+ ##
+ # Creates a new TarWriter that will write to +io+
+
def initialize(io)
@io = io
@closed = false
end
- def add_file(name, mode)
+ ##
+ # Adds file +name+ with permissions +mode+, and yields an IO for writing the
+ # file to
+
+ def add_file(name, mode) # :yields: io
check_closed
raise Gem::Package::NonSeekableIO unless @io.respond_to? :pos=
@@ -90,7 +128,11 @@ class Gem::Package::TarWriter
self
end
- def add_file_simple(name, mode, size)
+ ##
+ # Add file +name+ with permissions +mode+ +size+ bytes long. Yields an IO
+ # to write the file to.
+
+ def add_file_simple(name, mode, size) # :yields: io
check_closed
name, prefix = split_name name
@@ -112,10 +154,16 @@ class Gem::Package::TarWriter
self
end
+ ##
+ # Raises IOError if the TarWriter is closed
+
def check_closed
raise IOError, "closed #{self.class}" if closed?
end
+ ##
+ # Closes the TarWriter
+
def close
check_closed
@@ -125,16 +173,25 @@ class Gem::Package::TarWriter
@closed = true
end
+ ##
+ # Is the TarWriter closed?
+
def closed?
@closed
end
+ ##
+ # Flushes the TarWriter's IO
+
def flush
check_closed
@io.flush if @io.respond_to? :flush
end
+ ##
+ # Creates a new directory in the tar file +name+ with +mode+
+
def mkdir(name, mode)
check_closed
@@ -149,6 +206,9 @@ class Gem::Package::TarWriter
self
end
+ ##
+ # Splits +name+ into a name and prefix that can fit in the TarHeader
+
def split_name(name) # :nodoc:
raise Gem::Package::TooLongFileName if name.size > 256
@@ -169,7 +229,7 @@ class Gem::Package::TarWriter
name = newname
if name.size > 100 or prefix.size > 155 then
- raise Gem::Package::TooLongFileName
+ raise Gem::Package::TooLongFileName
end
end