Class: RUtilAnts::Archive::ObjectReader
- Inherits:
-
Object
- Object
- RUtilAnts::Archive::ObjectReader
- Defined in:
- lib/rUtilAnts/Archive.rb
Overview
Class used to read a Ruby object
Constant Summary collapse
- OBJECT_HEADER_SIZE =
Size of the object header
5
Instance Method Summary collapse
-
#get ⇒ Object
Get the next object encrypted.
-
#initialize(iPassword, iSalt, iFile) ⇒ ObjectReader
constructor
Constructor.
Constructor Details
#initialize(iPassword, iSalt, iFile) ⇒ ObjectReader
Constructor
- Parameters
-
iPassword (String): Password encrypting data
-
iSalt (String): Salt encoding data
-
iFile (IO): The IO that will send encrypted data
154 155 156 157 |
# File 'lib/rUtilAnts/Archive.rb', line 154 def initialize(iPassword, iSalt, iFile) @StringReader = StringReader.new(iPassword, iSalt, iFile) @BufferRead = '' end |
Instance Method Details
#get ⇒ Object
Get the next object encrypted
- Return
-
Object: The next object encrypted (or nil if none)
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/rUtilAnts/Archive.rb', line 163 def get rObject = nil # Read the size first while (@BufferRead.size < OBJECT_HEADER_SIZE) @BufferRead.concat(@StringReader.get) end lObjectType = @BufferRead[0..0] lObjectSize = @BufferRead[1..OBJECT_HEADER_SIZE-1].unpack('l')[0] # Then read the data while (@BufferRead.size < OBJECT_HEADER_SIZE+lObjectSize) @BufferRead.concat(@StringReader.get) end case lObjectType when TYPE_OBJECT rObject = Marshal.load(@BufferRead[OBJECT_HEADER_SIZE..OBJECT_HEADER_SIZE+lObjectSize-1]) when TYPE_STRING rObject = @BufferRead[OBJECT_HEADER_SIZE..OBJECT_HEADER_SIZE+lObjectSize-1] else raise RuntimeError.new("Unknown object type: #{lObjectType}") end @BufferRead = @BufferRead[OBJECT_HEADER_SIZE+lObjectSize..-1] return rObject end |