Skip to content

Commit 83fa900

Browse files
author
lakscastro
committed
(#85) Apply PR fixes
1 parent 0648b7e commit 83fa900

3 files changed

Lines changed: 10 additions & 14 deletions

File tree

android/src/main/kotlin/io/lakscastro/sharedstorage/storageaccessframework/DocumentFileApi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ internal class DocumentFileApi(private val plugin: SharedStoragePlugin) :
322322
result: MethodChannel.Result,
323323
uri: String,
324324
content: ByteArray,
325-
mode: String,
325+
mode: String
326326
) {
327327
try {
328328
plugin.context.contentResolver.openOutputStream(Uri.parse(uri), mode)?.apply {

docs/Usage/Storage Access Framework.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ Write to a file using raw bytes `Uint8List`.
223223

224224
Given the document uri, opens the file in the specified `mode` and writes the `bytes` to it.
225225

226-
`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.
226+
`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.
227227

228228
```dart
229229
final Uri documentUri = ...
@@ -576,7 +576,6 @@ You should provide either `content` or `bytes`, if both `bytes` will be used.
576576

577577
`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.
578578

579-
580579
```dart
581580
final Uri documentUri = ...
582581
final String fileContent = 'My File Content';
@@ -596,14 +595,14 @@ final bool? success = writeToFile(
596595
);
597596
598597
/// Write to a file using a [Uint8List] as file contents [bytes]
599-
final DocumentFile? createdFile = writeToFile(
598+
final bool? success = writeToFile(
600599
documentUri,
601600
content: Uint8List.fromList(fileContent.codeUnits),
602601
mode: FileMode.write,
603602
);
604603
605604
/// Append to a file using a [Uint8List] as file contents [bytes]
606-
final DocumentFile? createdFile = writeToFile(
605+
final bool? success = writeToFile(
607606
documentUri,
608607
content: Uint8List.fromList(fileContent.codeUnits),
609608
mode: FileMode.append,

lib/src/saf/saf.dart

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ Future<DocumentFile?> createDirectory(Uri parentUri, String displayName) async {
202202
}
203203

204204
/// {@template sharedstorage.saf.createFile}
205-
/// Convenient method to create files using either String or raw bytes.
205+
/// Convenient method to create files using either [String] or raw bytes [Uint8List].
206206
///
207207
/// Under the hood this method calls `createFileAsString` or `createFileAsBytes`
208208
/// depending on which argument is passed.
@@ -283,7 +283,7 @@ Future<DocumentFile?> createFileAsString(
283283
}
284284

285285
/// {@template sharedstorage.saf.writeToFile}
286-
/// Convenient method to write to a file using either String or raw bytes.
286+
/// Convenient method to write to a file using either [String] or raw bytes [Uint8List].
287287
///
288288
/// Under the hood this method calls `writeToFileAsString` or `writeToFileAsBytes`
289289
/// depending on which argument is passed.
@@ -327,14 +327,11 @@ Future<bool?> writeToFileAsBytes(
327327
required Uint8List bytes,
328328
FileMode? mode,
329329
}) async {
330-
var writeMode = 'wt';
331-
332-
if (mode == FileMode.append || mode == FileMode.writeOnlyAppend) {
333-
writeMode = 'wa';
334-
}
330+
final writeMode =
331+
mode == FileMode.append || mode == FileMode.writeOnlyAppend ? 'wa' : 'wt';
335332

336333
final args = <String, dynamic>{
337-
'uri': uri.toString(),
334+
'uri': '$uri',
338335
'content': bytes,
339336
'mode': writeMode,
340337
};
@@ -344,7 +341,7 @@ Future<bool?> writeToFileAsBytes(
344341

345342
/// {@template sharedstorage.saf.writeToFileAsString}
346343
/// Convenient method to write to a file.
347-
/// using `content` as String instead Uint8List.
344+
/// using `content` as [String] instead [Uint8List].
348345
/// {@endtemplate}
349346
Future<bool?> writeToFileAsString(
350347
Uri uri, {

0 commit comments

Comments
 (0)