This pull request introduces a change to the save_segment method in esptool.py. The main modification ensures that the segment.data is properly encoded as bytes if it is provided as a string. This change addresses potential issues when writing segment data to the image file, ensuring compatibility and preventing runtime errors due to incorrect data types.
Motivation
This enhancement is crucial as it maintains data integrity when saving segments, especially when segment data may inadvertently be in string format. It allows for more robust handling of input data types, ensuring that the writing process to the image file functions smoothly without requiring external type checks.
Related
Fixes
Related pull requests:
Documentation link:
Testing
I tested the changes by creating a new virtual environment and running the esptool with various segment data types (both string and bytes). All tests confirmed that the save_segment method works correctly, successfully writing segment data to the image file without any type-related errors.
Checklist
Before submitting a Pull Request, please ensure the following:
[x] 🚨 This PR does not introduce breaking changes.
[/] All CI checks (GH Actions) pass.
[/] Documentation is updated as needed.
[/] Tests are updated or added as necessary.
[x] Code is well-commented, especially in complex areas.
[x] Git history is clean — commits are squashed to the minimum necessary.
Description
This pull request introduces a change to the
save_segment
method inesptool.py
. The main modification ensures that thesegment.data
is properly encoded as bytes if it is provided as a string. This change addresses potential issues when writing segment data to the image file, ensuring compatibility and preventing runtime errors due to incorrect data types.Motivation
This enhancement is crucial as it maintains data integrity when saving segments, especially when segment data may inadvertently be in string format. It allows for more robust handling of input data types, ensuring that the writing process to the image file functions smoothly without requiring external type checks.
Related
Testing
I tested the changes by creating a new virtual environment and running the
esptool
with various segment data types (both string and bytes). All tests confirmed that thesave_segment
method works correctly, successfully writing segment data to the image file without any type-related errors.Checklist
Before submitting a Pull Request, please ensure the following: