Sha256: bad201ae77e37c84742a84d7384963412002f7b390e89c5a24878011e537628e
Contents?: true
Size: 1.46 KB
Versions: 24
Compression:
Stored size: 1.46 KB
Contents
# frozen_string_literal: true module Hyrax class PersistDerivatives < Hydra::Derivatives::PersistOutputFileService # Persists a derivative to the local file system. # This Service conforms to the signature of `Hydra::Derivatives::PersistOutputFileService`. # This service is an alternative to the default Hydra::Derivatives::PersistOutputFileService. # This service will always update existing and does not do versioning of persisted files. # # @param [#read] stream the derivative filestream # @param [Hash] directives # @option directives [String] :url a url to the file destination def self.call(stream, directives) output_file(directives) do |output| IO.copy_stream(stream, output) end end # Open the output file to write and yield the block to the # file. It makes the directories in the path if necessary. def self.output_file(directives, &blk) raise ArgumentError, "No :url was provided in the transcoding directives" unless directives.key?(:url) uri = URI(directives.fetch(:url)) raise ArgumentError, "Must provide a file uri" unless uri.scheme == 'file' output_file_dir = File.dirname(uri.path) FileUtils.mkdir_p(output_file_dir) unless File.directory?(output_file_dir) File.open(uri.path, 'wb', &blk) end ## # @deprecated def self.derivative_path_factory Deprecation.warn("Use 'Hyrax::DerivativePath' instead.") DerivativePath end end end
Version data entries
24 entries across 24 versions & 1 rubygems