Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readIntoSync/readAsBytes/readAsBytesSync all do not read the full file size #55695

Closed
gumibears opened this issue May 12, 2024 · 2 comments
Closed

Comments

@gumibears
Copy link

Given a file "1.bin". Windows/Android/Python program/C program all read it as having 381536 bytes. When I transfer 1.bin, it programs my esp8266 correctly.
The below methods in DART all print out 381136 bytes. This causes my esp8266 to behave incorrectly. I am not sure why it does not read the remaining 400 bytes consistently no matter what i do.

Example code:
var file = File(_filePath!);
var buffer = List.filled(400000, 0xFF);
print('BUFFER: $buffer');
var raf = file.openSync();
var counter = 0;
for (int i = 0; i < 400000; i += 4096) {
print('Reading from $i to ${i + 4096}');
counter += raf.readIntoSync(buffer, i, i+4096); // Read bytes into the buffer
print('BUFFER: $counter');
}

or

Uint8List fileBytes = file.readAsBytesSync();
print(fileBytes.length);
or
Uint8List fileBytes = await file.readAsBytes();
print(fileBytes.length);

@julemand101
Copy link
Contributor

When I transfer 1.bin

How do you transfer the file?

@gumibears
Copy link
Author

ok i figured it out. I was using a much older version of filepicker (5.2.6) from an example code in pubspec.yaml. I updated it to 8.0.3 and it works as intended. sorry for the trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants