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 (TrueClass, FalseClass)

    (false) Check if file exist



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

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

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

  File.open(path, "wb"){ |f| f.seek(size - 1); f.write("\0") }

  self
end