Class: RUtilAnts::Archive::ObjectWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/rUtilAnts/Archive.rb

Overview

Class used to write a Ruby object

Instance Method Summary collapse

Constructor Details

#initialize(iPassword, iSalt, oFile) ⇒ ObjectWriter

Constructor

Parameters
  • iPassword (String): Password encrypting data

  • iSalt (String): Salt encoding data

  • oFile (IO): The IO that will receive encrypted data



113
114
115
# File 'lib/rUtilAnts/Archive.rb', line 113

def initialize(iPassword, iSalt, oFile)
  @StringWriter = StringWriter.new(iPassword, iSalt, oFile)
end

Instance Method Details

#<<(iObject) ⇒ Object

Add an object to write

Parameters
  • iObject (Object): The object to write



121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/rUtilAnts/Archive.rb', line 121

def <<(iObject)
  lStrType = nil
  lStrObject = nil
  if (iObject.is_a?(String))
    lStrType = TYPE_STRING
    lStrObject = iObject
  else
    lStrType = TYPE_OBJECT
    lStrObject = Marshal.dump(iObject)
  end
  # Write it along with its length
  @StringWriter << (lStrType + [lStrObject.size].pack('l') + lStrObject)
end

#flushObject

Flush



136
137
138
# File 'lib/rUtilAnts/Archive.rb', line 136

def flush
  @StringWriter.flush
end