Sha256: e03fb42b363c1154a7f629332c1345c4079470679e000fe5d410960366dc219b

Contents?: true

Size: 663 Bytes

Versions: 1

Compression:

Stored size: 663 Bytes

Contents

module IOStreams
  module File
    class Writer
      # Write to a named file
      #
      # Note:
      #   If an exception is raised whilst the file is being written to the file is removed to
      #   prevent incomplete / partial files from being created.
      def self.open(file_name, **args, &block)
        raise(ArgumentError, 'File name must be a string') unless file_name.is_a?(String)

        IOStreams::File::Path.mkpath(file_name)
        begin
          ::File.open(file_name, 'wb', &block)
        rescue StandardError => e
          ::File.unlink(file_name) if ::File.exist?(file_name)
          raise(e)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
iostreams-0.20.3 lib/io_streams/file/writer.rb