From dfb991498284f3ca4b57d9d763bc54d6cf46804c Mon Sep 17 00:00:00 2001 From: Joe Eli McIlvain Date: Tue, 7 Mar 2017 18:21:58 -0800 Subject: [PATCH] Fix buffered.Reader.append to accept any ByteSeq. This is an issue of principle-of-least-surprise, since buffered.Writer emits ByteSeqs in its output, so having buffered.Reader accept ByteSeqs at its input makes it symmetrical and least surprising. This doesn't break any user code, since it only makes an argument type more general, and does not make any return types more general. --- packages/buffered/reader.pony | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/buffered/reader.pony b/packages/buffered/reader.pony index f3f37b5211..c9faa29648 100644 --- a/packages/buffered/reader.pony +++ b/packages/buffered/reader.pony @@ -79,12 +79,20 @@ class Reader _chunks.clear() _available = 0 - fun ref append(data: Array[U8] val) => + fun ref append(data: ByteSeq) => """ Add a chunk of data. """ - _available = _available + data.size() - _chunks.push((data, 0)) + let data_array: Array[U8] val = + match data + | let data': Array[U8] val => data' + | let data': String => data'.array() + else // unreachable + recover val Array[U8] end + end + + _available = _available + data_array.size() + _chunks.push((data_array, 0)) fun ref skip(n: USize) ? => """