rainbows.git  about / heads / tags
Unicorn for sleepy apps and slow clients
blob 3bb4dd726b94237cde72ec32f87a5f788d848fa9 354 bytes (raw)
$ git show v0.97.0:lib/rainbows/byte_slice.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
 
# -*- encoding: binary -*-
# :enddoc:
module Rainbows::ByteSlice
  if String.method_defined?(:encoding)
    def byte_slice(buf, range)
      if buf.encoding != Encoding::BINARY
        buf.dup.force_encoding(Encoding::BINARY)[range]
      else
        buf[range]
      end
    end
  else
    def byte_slice(buf, range)
      buf[range]
    end
  end
end

git clone https://yhbt.net/rainbows.git