Sha256: 01f9cef5f6cdc22397628e3747e08c0e87dd7964dec88454fcdd086026c9b07e

Contents?: true

Size: 1.26 KB

Versions: 4

Compression:

Stored size: 1.26 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 entry's source to the destination via a buffer.
    #
    # @param dest [#write] An IO-like destination to write to.
    def write_to(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 symlink on the disk?
    def symlink?
      ::File.symlink?(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

4 entries across 4 versions & 1 rubygems

Version Path
ro-crate-0.5.2 lib/ro_crate/model/entry.rb
ro-crate-0.5.1 lib/ro_crate/model/entry.rb
ro-crate-0.5.0 lib/ro_crate/model/entry.rb
ro-crate-0.4.17 lib/ro_crate/model/entry.rb