Sha256: 6debe4572ea5581b42a9364ac07211a102d5f8eaaaabf009adcb183bf81fddb3

Contents?: true

Size: 1.12 KB

Versions: 10

Compression:

Stored size: 1.12 KB

Contents

module ROCrate
  ##
  # A class to represent a "physical" file or directory within an RO-Crate.
  # It handles the actual reading/writing of bytes.
  class Entry
    attr_reader :source

    ##
    # Create a new Entry.
    #
    # @param source [#read] An IO-like source that can be read.
    def initialize(source)
      @source = source
    end

    ##
    # Write the source to the destination via a buffer.
    #
    # @param dest [#write] An IO-like destination to write to.
    def write(dest)
      input = source
      input = input.open('rb') if input.is_a?(Pathname)
      while (buff = input.read(4096))
        dest.write(buff)
      end
    end

    ##
    # Read from the source.
    #
    def read
      source.read
    end

    ##
    # Does this Entry point to a directory on the disk?
    def directory?
      ::File.directory?(source) rescue false
    end

    ##
    # Does this Entry point to a remote resource?
    def remote?
      false
    end

    def path
      if source.is_a?(Pathname)
        source.to_s
      elsif source.respond_to?(:path)
        source.path
      else
        nil
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ro-crate-0.4.11 lib/ro_crate/model/entry.rb
ro-crate-0.4.10 lib/ro_crate/model/entry.rb
ro-crate-0.4.9 lib/ro_crate/model/entry.rb
ro-crate-0.4.8 lib/ro_crate/model/entry.rb
ro-crate-0.4.7 lib/ro_crate/model/entry.rb
ro-crate-0.4.6 lib/ro_crate/model/entry.rb
ro-crate-0.4.5 lib/ro_crate/model/entry.rb
ro-crate-0.4.4 lib/ro_crate/model/entry.rb
ro-crate-0.4.3 lib/ro_crate/model/entry.rb
ro-crate-0.4.2 lib/ro_crate/model/entry.rb