Class: Archiverb::File
- Inherits:
-
Object
- Object
- Archiverb::File
- Defined in:
- lib/archiverb/file.rb
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
the directory path leading to the file.
-
#gid ⇒ Object
readonly
The user id and group id of the file.
-
#io ⇒ Object
readonly
the raw io object, you can add to it prior to calling read.
-
#mode ⇒ Object
octal mode.
-
#mtime ⇒ Time
readonly
Modification time.
-
#name ⇒ Object
readonly
the basename of the file.
-
#path ⇒ Object
readonly
the path and name of the file.
-
#size ⇒ Object
(also: #bytes)
readonly
Returns the value of attribute size.
-
#stat ⇒ Object
readonly
[Archiverb::Stat].
-
#uid ⇒ Object
readonly
The user id and group id of the file.
Instance Method Summary collapse
-
#close ⇒ Object
Prevents future access to the contents of the file and hopefully frees up memory.
-
#initialize(name, io, buff = io, stat = nil, &blk) ⇒ File
constructor
A new instance of File.
-
#read ⇒ Object
initialize(io, stat).
Constructor Details
#initialize(name, io, buff = io, stat = nil, &blk) ⇒ File
Returns a new instance of File.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/archiverb/file.rb', line 27 def initialize(name, io, buff=io, stat=nil, &blk) buff,stat = stat, buff if buff.is_a?(Stat) || buff.is_a?(::File::Stat) stat = Stat.new(io) if stat.nil? @name = ::File.basename(name) @dir = ::File.dirname(name) @path = name @mtime = stat.mtime.is_a?(Fixnum) ? Time.at(stat.mtime) : stat.mtime @uid = stat.uid @gid = stat.gid @mode = stat.mode @size = stat.size @readbuff = buff @readback = blk unless blk.nil? @io = io.is_a?(String) ? StringIO.new(io) : io @io.binmode if @io.respond_to?(:path) && ::File.directory?(@io.path) @size = 0 end @stat = stat end |
Instance Attribute Details
#dir ⇒ Object (readonly)
the directory path leading to the file
8 9 10 |
# File 'lib/archiverb/file.rb', line 8 def dir @dir end |
#gid ⇒ Object (readonly)
The user id and group id of the file. Set #stat.uname and #stat.gname to force ownership by name rather than id.
15 16 17 |
# File 'lib/archiverb/file.rb', line 15 def gid @gid end |
#io ⇒ Object (readonly)
the raw io object, you can add to it prior to calling read
23 24 25 |
# File 'lib/archiverb/file.rb', line 23 def io @io end |
#mode ⇒ Object
octal mode
12 13 14 |
# File 'lib/archiverb/file.rb', line 12 def mode @mode end |
#mtime ⇒ Time (readonly)
Returns modification time.
17 18 19 |
# File 'lib/archiverb/file.rb', line 17 def mtime @mtime end |
#name ⇒ Object (readonly)
the basename of the file
6 7 8 |
# File 'lib/archiverb/file.rb', line 6 def name @name end |
#path ⇒ Object (readonly)
the path and name of the file
10 11 12 |
# File 'lib/archiverb/file.rb', line 10 def path @path end |
#size ⇒ Object (readonly) Also known as: bytes
Returns the value of attribute size.
19 20 21 |
# File 'lib/archiverb/file.rb', line 19 def size @size end |
#stat ⇒ Object (readonly)
- Archiverb::Stat
25 26 27 |
# File 'lib/archiverb/file.rb', line 25 def stat @stat end |
#uid ⇒ Object (readonly)
The user id and group id of the file. Set #stat.uname and #stat.gname to force ownership by name rather than id.
15 16 17 |
# File 'lib/archiverb/file.rb', line 15 def uid @uid end |
Instance Method Details
#close ⇒ Object
Prevents future access to the contents of the file and hopefully frees up memory.
71 72 73 |
# File 'lib/archiverb/file.rb', line 71 def close @raw = nil end |
#read ⇒ Object
initialize(io, stat)
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/archiverb/file.rb', line 50 def read return @raw if @raw if @readback && @readbuff @readback.call(@readbuff) @readbuff.close_write end @io.rewind unless @stat.pipe? if @io.respond_to?(:path) && ::File.directory?(@io.path) @raw = "" else @raw = @io.read @size = @raw.length end @io.close @raw end |