File: count_bytes_remaining.rb

package info (click to toggle)
ruby-bindata 2.4.14-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 600 kB
  • sloc: ruby: 8,566; makefile: 4
file content (34 lines) | stat: -rw-r--r-- 733 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
require "bindata/base_primitive"

module BinData
  # Counts the number of bytes remaining in the input stream from the current
  # position to the end of the stream.  This only makes sense for seekable
  # streams.
  #
  #   require 'bindata'
  #
  #   class A < BinData::Record
  #     count_bytes_remaining :bytes_remaining
  #     string :all_data, read_length: :bytes_remaining
  #   end
  #
  #   obj = A.read("abcdefghij")
  #   obj.all_data #=> "abcdefghij"
  #
  class CountBytesRemaining < BinData::BasePrimitive
    #---------------
    private

    def value_to_binary_string(val)
      ""
    end

    def read_and_return_value(io)
      io.num_bytes_remaining
    end

    def sensible_default
      0
    end
  end
end