diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-07-06 09:58:40 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-07-06 10:05:13 +0000 |
commit | d2f240d7ea11738ba889668a669ffb7845d06e7b (patch) | |
tree | 020802df1f92f750ee91f0834c09bac0e304c3a2 /lib/rainbows/byte_slice.rb | |
parent | 0283928fca45a012b31662b30b49990dac2aae18 (diff) | |
download | rainbows-d2f240d7ea11738ba889668a669ffb7845d06e7b.tar.gz |
Fortunately this only affects the hardly-used FiberSpawn and FiberPool concurrency models, and also unreleased revisions of Rev. 1.9 encoding is tricky to handle right when doing I/O in Ruby...
Diffstat (limited to 'lib/rainbows/byte_slice.rb')
-rw-r--r-- | lib/rainbows/byte_slice.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/rainbows/byte_slice.rb b/lib/rainbows/byte_slice.rb new file mode 100644 index 0000000..09d1188 --- /dev/null +++ b/lib/rainbows/byte_slice.rb @@ -0,0 +1,16 @@ +# -*- encoding: binary -*- +module Rainbows::ByteSlice + if String.method_defined?(:encoding) + def byte_slice(buf, range) + if buf.encoding != Encoding::BINARY + buf.dup.force_encoding(Encoding::BINARY).slice!(range) + else + buf[range] + end + end + else + def byte_slice(buf, range) + buf[range] + end + end +end |