Sha256: f8e2185344d1adfc079f3ee48cfd5d9f573bd422f2e1e93eb245e0a49a245206

Contents?: true

Size: 619 Bytes

Versions: 19

Compression:

Stored size: 619 Bytes

Contents

# frozen_string_literal: true

module Grape
  module ServeStream
    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

19 entries across 19 versions & 2 rubygems

Version Path
grape-2.3.0 lib/grape/serve_stream/file_body.rb
grape-2.2.0 lib/grape/serve_stream/file_body.rb
grape-2.1.3 lib/grape/serve_stream/file_body.rb
grape-2.1.2 lib/grape/serve_stream/file_body.rb
grape-2.1.1 lib/grape/serve_stream/file_body.rb
grape-2.1.0 lib/grape/serve_stream/file_body.rb
grape-2.0.0 lib/grape/serve_stream/file_body.rb
grape-1.8.0 lib/grape/serve_stream/file_body.rb
grape-1.7.1 lib/grape/serve_stream/file_body.rb
grape-1.7.0 lib/grape/serve_stream/file_body.rb
grape-1.6.2 lib/grape/serve_stream/file_body.rb
grape-1.6.1 lib/grape/serve_stream/file_body.rb
grape-1.6.0 lib/grape/serve_stream/file_body.rb
grape-1.5.3 lib/grape/serve_stream/file_body.rb
grape-1.5.2 lib/grape/serve_stream/file_body.rb
grape-1.5.1 lib/grape/serve_stream/file_body.rb
grape-1.5.0 lib/grape/serve_stream/file_body.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.4.0/lib/grape/serve_stream/file_body.rb
grape-1.4.0 lib/grape/serve_stream/file_body.rb