Sha256: 253f45f9e730d9bdd1f567301f7aca5f3e8e8f7c0580b09f0313bee9810726b6

Contents?: true

Size: 617 Bytes

Versions: 4

Compression:

Stored size: 617 Bytes

Contents

# frozen_string_literal: true

module Grape
  module ServeFile
    CHUNK_SIZE = 16_384

    # Class helps send file through API
    class FileBody
      attr_reader :path

      # @param path [String]
      def initialize(path)
        @path = path
      end

      # Need for Rack::Sendfile middleware
      #
      # @return [String]
      def to_path
        path
      end

      def each
        File.open(path, 'rb') do |file|
          while (chunk = file.read(CHUNK_SIZE))
            yield chunk
          end
        end
      end

      def ==(other)
        path == other.path
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
grape-1.3.3 lib/grape/serve_file/file_body.rb
grape-1.3.2 lib/grape/serve_file/file_body.rb
grape-1.3.1 lib/grape/serve_file/file_body.rb
grape-1.3.0 lib/grape/serve_file/file_body.rb