Skip to content

Commit

Permalink
Cap the number of chunks written by StreamOutputRange.put at two.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-ludwig committed Jun 26, 2017
1 parent 321e4d8 commit e1df68e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions stream/vibe/stream/wrapper.d
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,13 @@ struct StreamOutputRange(OutputStream)

void put(const(ubyte)[] bts)
{
// avoid writing more chunks than necessary
if (bts.length + m_fill >= m_data.length * 2) {
flush();
m_stream.write(bts);
return;
}

while (bts.length) {
auto len = min(m_data.length - m_fill, bts.length);
m_data[m_fill .. m_fill + len] = bts[0 .. len];
Expand Down

0 comments on commit e1df68e

Please sign in to comment.