Sha256: 386d239d5054b58881deec957e6d1d879cd0e2442981eaaeb2772024673818ba

Contents?: true

Size: 862 Bytes

Versions: 4

Compression:

Stored size: 862 Bytes

Contents

# Aruba
module Aruba
  # Platforms
  module Platforms
    # 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.
    #
    # @private
    class ArubaFixedSizeFileCreator
      # Write File
      #
      # @param [String] path
      #   The path to write content to
      #
      # @param [Numeric] size
      #   The size of the file
      #
      # @param [Boolean] check_presence (false)
      #   Check if file exist
      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
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
aruba-1.0.0 lib/aruba/platforms/aruba_fixed_size_file_creator.rb
aruba-1.0.0.pre.alpha.5 lib/aruba/platforms/aruba_fixed_size_file_creator.rb
aruba-1.0.0.pre.alpha.4 lib/aruba/platforms/aruba_fixed_size_file_creator.rb
aruba-1.0.0.pre.alpha.3 lib/aruba/platforms/aruba_fixed_size_file_creator.rb