Sha256: 0f21eda09cfcbfdf2b1b76f8248b85e82614574f21281fdf76efcd873d9442f4

Contents?: true

Size: 586 Bytes

Versions: 20

Compression:

Stored size: 586 Bytes

Contents

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

20 entries across 20 versions & 2 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.2.5/lib/grape/serve_file/file_body.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/grape-1.2.5/lib/grape/serve_file/file_body.rb
grape-1.2.5 lib/grape/serve_file/file_body.rb
grape-1.2.4 lib/grape/serve_file/file_body.rb
grape-1.2.3 lib/grape/serve_file/file_body.rb
grape-1.2.2 lib/grape/serve_file/file_body.rb
grape-1.2.1 lib/grape/serve_file/file_body.rb
grape-1.2.0 lib/grape/serve_file/file_body.rb
grape-1.1.0 lib/grape/serve_file/file_body.rb
grape-1.0.3 lib/grape/serve_file/file_body.rb
grape-1.0.2 lib/grape/serve_file/file_body.rb
grape-1.0.1 lib/grape/serve_file/file_body.rb
grape-1.0.0 lib/grape/serve_file/file_body.rb
grape-0.19.2 lib/grape/serve_file/file_body.rb
grape-0.19.1 lib/grape/serve_file/file_body.rb
grape-0.19.0 lib/grape/serve_file/file_body.rb
grape-0.18.0 lib/grape/serve_file/file_body.rb
grape-0.17.0 lib/grape/serve_file/file_body.rb
grape-0.16.2 lib/grape/serve_file/file_body.rb
grape-0.16.1 lib/grape/serve_file/file_body.rb