Sha256: c53129d68ccf18af95eb5cac0f47dd3036824b95e38c20552a1ff593a2ec84fa

Contents?: true

Size: 1.12 KB

Versions: 2

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

2 entries across 2 versions & 1 rubygems

Version Path
ro-crate-0.4.1 lib/ro_crate/model/entry.rb
ro-crate-0.4.0 lib/ro_crate/model/entry.rb