@@ -24,33 +24,29 @@ template <class T>
24
24
class StreamCopyT {
25
25
public:
26
26
StreamCopyT (Allocator &allocator, int bufferSize = DEFAULT_BUFFER_SIZE)
27
- : _allocator(allocator) {
27
+ : _allocator(allocator), buffer_size(bufferSize) {
28
28
TRACED ();
29
- this ->buffer_size = bufferSize;
30
29
begin ();
31
30
}
32
31
StreamCopyT (Print &to, AudioStream &from,
33
32
int bufferSize = DEFAULT_BUFFER_SIZE,
34
33
Allocator &allocator = DefaultAllocator)
35
- : _allocator(allocator) {
34
+ : _allocator(allocator), buffer_size(bufferSize) {
36
35
TRACED ();
37
- this ->buffer_size = bufferSize;
38
36
begin (to, from);
39
37
}
40
38
41
39
StreamCopyT (Print &to, Stream &from, int bufferSize = DEFAULT_BUFFER_SIZE,
42
40
Allocator &allocator = DefaultAllocator)
43
- : _allocator(allocator) {
41
+ : _allocator(allocator), buffer_size(bufferSize) {
44
42
TRACED ();
45
- this ->buffer_size = bufferSize;
46
43
begin (to, from);
47
44
}
48
45
49
46
StreamCopyT (int bufferSize = DEFAULT_BUFFER_SIZE,
50
47
Allocator &allocator = DefaultAllocator)
51
- : _allocator(allocator) {
48
+ : _allocator(allocator), buffer_size(bufferSize) {
52
49
TRACED ();
53
- this ->buffer_size = bufferSize;
54
50
begin ();
55
51
}
56
52
@@ -147,13 +143,13 @@ class StreamCopyT {
147
143
if (check_available) {
148
144
len = available ();
149
145
}
150
- size_t bytes_to_read = bytes ;
146
+ size_t bytes_to_read = len ;
151
147
size_t bytes_read = 0 ;
152
148
153
149
if (len > 0 ) {
154
150
bytes_to_read = min (len, static_cast <size_t >(buffer_size));
155
151
// don't overflow buffer
156
- if (to_write > 0 ) {
152
+ if (check_available_for_write && to_write > 0 ) {
157
153
bytes_to_read = min ((int )bytes_to_read, to_write);
158
154
}
159
155
@@ -312,7 +308,7 @@ class StreamCopyT {
312
308
// / resizes the copy buffer
313
309
void resize (int len) {
314
310
buffer_size = len;
315
- buffer.resize (buffer_size );
311
+ buffer.resize (len );
316
312
}
317
313
318
314
// / deactivate/activate copy - active by default
0 commit comments