Class: RUtilAnts::Archive::FilesReader

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

Overview

Class used to read files and directories

Instance Method Summary collapse

Constructor Details

#initialize(iPassword, iSalt, iFile) ⇒ FilesReader

Constructor

Parameters
  • iPassword (String): Password encrypting data

  • iSalt (String): Salt encoding data

  • iFile (IO): The IO that will send encrypted data



318
319
320
# File 'lib/rUtilAnts/Archive.rb', line 318

def initialize(iPassword, iSalt, iFile)
  @ObjectReader = ObjectReader.new(iPassword, iSalt, iFile)
end

Instance Method Details

#readObject

Read the files and write them in the current directory



323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# File 'lib/rUtilAnts/Archive.rb', line 323

def read
  # First, read the archive header
  lEmptyDirs, lNbrFiles, lTotalSize = @ObjectReader.get
  # Create the empty directories
  lEmptyDirs.each do |iDirName|
    FileUtils::mkdir_p(iDirName)
  end
  # Read each file
  lDecodedSize = 0
  lNbrFiles.times do |iIdxFile|
    lFileName, lNbrChunks = @ObjectReader.get
    log_debug "Reading file #{lFileName} (#{lNbrChunks} chunks) ..."
    FileUtils::mkdir_p(File.dirname(lFileName))
    File.open(lFileName, 'wb') do |oFile|
      lNbrChunks.times do |iIdxChunk|
        lFileDataChunk = @ObjectReader.get
        oFile.write(lFileDataChunk)
        lDecodedSize += lFileDataChunk.size
        $stdout.write("#{(lDecodedSize*100)/lTotalSize} %\015")
      end
    end
  end
end