Class: Aruba::Platforms::ArubaFixedSizeFileCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/aruba/platforms/aruba_fixed_size_file_creator.rb

Overview

Create files with fixed size

This class is not meant to be used directly by users.

It uses a single null byte as content and really creates so called sparse files.

Instance Method Summary collapse

Instance Method Details

#call(path, size, check_presence) ⇒ Object

Write File

Parameters:

  • path (String)

    The path to write content to

  • size (Numeric)

    The size of the file

  • check_presence (Boolean)

    (false) Check if file exist



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/aruba/platforms/aruba_fixed_size_file_creator.rb', line 24

def call(path, size, check_presence)
  if check_presence && !Aruba.platform.file?(path)
    raise "Expected #{path} to be present"
  end

  Aruba.platform.mkdir(File.dirname(path))

  File.open(path, "wb") do |f|
    f.seek(size - 1)
    f.write("\0")
  end

  self
end