@@ -24,33 +24,29 @@ template <class T>
2424class StreamCopyT {
2525 public:
2626 StreamCopyT (Allocator &allocator, int bufferSize = DEFAULT_BUFFER_SIZE)
27- : _allocator(allocator) {
27+ : _allocator(allocator), buffer_size(bufferSize) {
2828 TRACED ();
29- this ->buffer_size = bufferSize;
3029 begin ();
3130 }
3231 StreamCopyT (Print &to, AudioStream &from,
3332 int bufferSize = DEFAULT_BUFFER_SIZE,
3433 Allocator &allocator = DefaultAllocator)
35- : _allocator(allocator) {
34+ : _allocator(allocator), buffer_size(bufferSize) {
3635 TRACED ();
37- this ->buffer_size = bufferSize;
3836 begin (to, from);
3937 }
4038
4139 StreamCopyT (Print &to, Stream &from, int bufferSize = DEFAULT_BUFFER_SIZE,
4240 Allocator &allocator = DefaultAllocator)
43- : _allocator(allocator) {
41+ : _allocator(allocator), buffer_size(bufferSize) {
4442 TRACED ();
45- this ->buffer_size = bufferSize;
4643 begin (to, from);
4744 }
4845
4946 StreamCopyT (int bufferSize = DEFAULT_BUFFER_SIZE,
5047 Allocator &allocator = DefaultAllocator)
51- : _allocator(allocator) {
48+ : _allocator(allocator), buffer_size(bufferSize) {
5249 TRACED ();
53- this ->buffer_size = bufferSize;
5450 begin ();
5551 }
5652
@@ -147,13 +143,13 @@ class StreamCopyT {
147143 if (check_available) {
148144 len = available ();
149145 }
150- size_t bytes_to_read = bytes ;
146+ size_t bytes_to_read = len ;
151147 size_t bytes_read = 0 ;
152148
153149 if (len > 0 ) {
154150 bytes_to_read = min (len, static_cast <size_t >(buffer_size));
155151 // don't overflow buffer
156- if (to_write > 0 ) {
152+ if (check_available_for_write && to_write > 0 ) {
157153 bytes_to_read = min ((int )bytes_to_read, to_write);
158154 }
159155
@@ -312,7 +308,7 @@ class StreamCopyT {
312308 // / resizes the copy buffer
313309 void resize (int len) {
314310 buffer_size = len;
315- buffer.resize (buffer_size );
311+ buffer.resize (len );
316312 }
317313
318314 // / deactivate/activate copy - active by default
0 commit comments