Sha256: 838b063dce01c418c90afa90ef9b2dde7618ebd71cb44da81cd54347a22e6da6

Contents?: true

Size: 871 Bytes

Versions: 5

Compression:

Stored size: 871 Bytes

Contents

module Aruba
  # Create things to make aruba work
  module Creators
    # 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.
    class ArubaFixedSizeFileCreator
      # Write File
      #
      # @param [String] path
      #   The path to write content to
      #
      # @param [Numeric] size
      #   The size of the file
      #
      # @param [TrueClass, FalseClass] check_presence (false)
      #   Check if file exist
      def write(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
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
aruba-0.8.1 lib/aruba/creators/aruba_fixed_size_file_creator.rb
aruba-0.8.0 lib/aruba/creators/aruba_fixed_size_file_creator.rb
aruba-0.8.0.pre3 lib/aruba/creators/aruba_fixed_size_file_creator.rb
aruba-0.8.0.pre2 lib/aruba/creators/aruba_fixed_size_file_creator.rb
aruba-0.8.0.pre lib/aruba/creators/aruba_fixed_size_file_creator.rb