File: readable.rb

package info (click to toggle)
ruby-http-form-data 2.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 204 kB
  • sloc: ruby: 861; makefile: 5
file content (40 lines) | stat: -rw-r--r-- 799 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true

module HTTP
  module FormData
    # Common behaviour for objects defined by an IO object.
    module Readable
      # Returns IO content.
      #
      # @return [String]
      def to_s
        rewind
        content = read
        rewind
        content
      end

      # Reads and returns part of IO content.
      #
      # @param [Integer] length Number of bytes to retrieve
      # @param [String] outbuf String to be replaced with retrieved data
      #
      # @return [String, nil]
      def read(length = nil, outbuf = nil)
        @io.read(length, outbuf)
      end

      # Returns IO size.
      #
      # @return [Integer]
      def size
        @io.size
      end

      # Rewinds the IO.
      def rewind
        @io.rewind
      end
    end
  end
end