-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
Add writeToFile, writeToFileAsBytes, writeToFileAsString #85
Conversation
result: MethodChannel.Result, | ||
uri: String, | ||
content: ByteArray, | ||
mode: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lib/src/saf/saf.dart
Outdated
@@ -281,6 +282,82 @@ Future<DocumentFile?> createFileAsString( | |||
); | |||
} | |||
|
|||
/// {@template sharedstorage.saf.writeToFile} | |||
/// Convenient method to write to a file using either String or raw bytes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Convenient method to write to a file using either String or raw bytes. | |
/// Convenient method to write to a file using either [String] or raw bytes [Uint8List]. |
You can also apply this change for createFile
function.
lib/src/saf/saf.dart
Outdated
} | ||
|
||
final args = <String, dynamic>{ | ||
'uri': uri.toString(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'uri': uri.toString(), | |
'uri': '$uri', |
lib/src/saf/saf.dart
Outdated
var writeMode = 'wt'; | ||
|
||
if (mode == FileMode.append || mode == FileMode.writeOnlyAppend) { | ||
writeMode = 'wa'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var writeMode = 'wt'; | |
if (mode == FileMode.append || mode == FileMode.writeOnlyAppend) { | |
writeMode = 'wa'; | |
} | |
final writeMode = | |
mode == FileMode.append || mode == FileMode.writeOnlyAppend ? 'wa' : 'wt'; |
lib/src/saf/saf.dart
Outdated
|
||
/// {@template sharedstorage.saf.writeToFileAsString} | ||
/// Convenient method to write to a file. | ||
/// using `content` as String instead Uint8List. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// using `content` as String instead Uint8List. | |
/// using `content` as [String] instead [Uint8List]. |
You can also apply this change for createFileAsString
function.
|
||
Given the document uri, opens the file in the specified `mode` and writes the `bytes` to it. | ||
|
||
`mode` represents the mode in which the file will be opened for writing. Use `FileMode.write` for truncating and `FileMode.append` for appending to the file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`mode` represents the mode in which the file will be opened for writing. Use `FileMode.write` for truncating and `FileMode.append` for appending to the file. | |
`mode` represents the mode in which the file will be opened for writing. Use `FileMode.write` for truncating (overwrite) and `FileMode.append` for appending to the file. |
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
); | ||
|
||
/// Write to a file using a [Uint8List] as file contents [bytes] | ||
final DocumentFile? createdFile = writeToFile( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final DocumentFile? createdFile = writeToFile( | |
final bool? success = writeToFile( |
Guess this function returns a boolean
representing the whether or not the operation was successful, if not let me know but I think it was just a typo.
); | ||
|
||
/// Append to a file using a [Uint8List] as file contents [bytes] | ||
final DocumentFile? createdFile = writeToFile( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final DocumentFile? createdFile = writeToFile( | |
final bool? success = writeToFile( |
Guess this function returns a boolean
representing the whether or not the operation was successful, if not let me know but I think it was just a typo.
Great work, I tested and it works gracefully on Android 10+ (Tested on Samsung A30 and POCO M4 PRO). I left some comments refering to small fixes related to the API documentation and code formatting. If you think something doesn't make sense just reply on it and lets discuss. You can also pull this branch: Thanks for the hard work! |
I am happy to hear that. I agree with all your changes! |
You did it! Happy to see your contribution here, I'll release on Any other requests or suggestions let me know! |
This PR implements #61.