diff --git a/README.md b/README.md
index e70ff1f..8457a53 100644
--- a/README.md
+++ b/README.md
@@ -190,6 +190,16 @@ const readFilePath = async () => {
console.log("data:", contents);
};
+
+const appendBinaryData = async () => {
+ // Here's an example of appending binary data, which should be sent to the plugin
+ // as base64 encoded, and without providing any `Encoding`
+ await Filesystem.appendFile({
+ path: "file.bin",
+ directory: Directory.Cache,
+ data: "VGhpcyBpcyBtZWFudCB0byByZXByZXNlbnQgYSBCaW5hcnkgRGF0YSBleGFtcGxlIGVuY29kZWQgaW4gQmFzZTY0Lg=="
+ });
+};
```
## API
diff --git a/packages/capacitor-plugin/README.md b/packages/capacitor-plugin/README.md
index 9a0c910..90c91df 100644
--- a/packages/capacitor-plugin/README.md
+++ b/packages/capacitor-plugin/README.md
@@ -171,6 +171,16 @@ const readFilePath = async () => {
console.log("data:", contents);
};
+
+const appendBinaryData = async () => {
+ // Here's an example of appending binary data, which should be sent to the plugin
+ // as base64 encoded, and without providing any `Encoding`.
+ await Filesystem.appendFile({
+ path: "file.bin",
+ directory: Directory.Cache,
+ data: "VGhpcyBpcyBtZWFudCB0byByZXByZXNlbnQgYSBCaW5hcnkgRGF0YSBleGFtcGxlIGVuY29kZWQgaW4gQmFzZTY0Lg=="
+ });
+};
```
## API
@@ -566,23 +576,23 @@ We recommend using the @capacitor/file-transfer plugin instead, in conjunction w
#### WriteFileOptions
-| Prop | Type | Description | Default | Since |
-| --------------- | ----------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- |
-| **`path`** | string | The path of the file to write | | 1.0.0 |
-| **`data`** | string \| Blob | The data to write Note: Blob data is only supported on Web. | | 1.0.0 |
-| **`directory`** | Directory | The `Directory` to store the file in | | 1.0.0 |
-| **`encoding`** | Encoding | The encoding to write the file in. If not provided, data is written as base64 encoded. Pass Encoding.UTF8 to write data as string | | 1.0.0 |
-| **`recursive`** | boolean | Whether to create any missing parent directories. | false | 1.0.0 |
+| Prop | Type | Description | Default | Since |
+| --------------- | ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------ | ----- |
+| **`path`** | string | The path of the file to write | | 1.0.0 |
+| **`data`** | string \| Blob | The data to write Note: Blob data is only supported on Web. | | 1.0.0 |
+| **`directory`** | Directory | The `Directory` to store the file in | | 1.0.0 |
+| **`encoding`** | Encoding | The encoding to write the file in. If not provided, binary data will be written. For this, you must provide data as base64 encoded, so that the plugin can decode it before writing to disk. If you do not provide encoding and use non-base64 data, an error will be thrown. Pass Encoding.UTF8 to write data as string | | 1.0.0 |
+| **`recursive`** | boolean | Whether to create any missing parent directories. | false | 1.0.0 |
#### AppendFileOptions
-| Prop | Type | Description | Since |
-| --------------- | ----------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
-| **`path`** | string | The path of the file to append | 1.0.0 |
-| **`data`** | string | The data to write | 1.0.0 |
-| **`directory`** | Directory | The `Directory` to store the file in | 1.0.0 |
-| **`encoding`** | Encoding | The encoding to write the file in. If not provided, data is written as base64 encoded. Pass Encoding.UTF8 to write data as string | 1.0.0 |
+| Prop | Type | Description | Since |
+| --------------- | ----------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
+| **`path`** | string | The path of the file to append | 1.0.0 |
+| **`data`** | string | The data to append | 1.0.0 |
+| **`directory`** | Directory | The `Directory` to store the file in | 1.0.0 |
+| **`encoding`** | Encoding | The encoding to append to the file. If not provided, binary data will be appended. For this, you must provide data as base64 encoded, so that the plugin can decode it before writing to disk. If you do not provide encoding and use non-base64 data, an error will be thrown. Pass Encoding.UTF8 to write data as string | 1.0.0 |
#### DeleteFileOptions
diff --git a/packages/capacitor-plugin/src/definitions.ts b/packages/capacitor-plugin/src/definitions.ts
index 72e4141..bfe98f8 100644
--- a/packages/capacitor-plugin/src/definitions.ts
+++ b/packages/capacitor-plugin/src/definitions.ts
@@ -154,8 +154,10 @@ export interface WriteFileOptions {
directory?: Directory;
/**
- * The encoding to write the file in. If not provided, data
- * is written as base64 encoded.
+ * The encoding to write the file in.
+ * If not provided, binary data will be written. For this, you must provide data as base64 encoded,
+ * so that the plugin can decode it before writing to disk.
+ * If you do not provide encoding and use non-base64 data, an error will be thrown.
*
* Pass Encoding.UTF8 to write data as string
*
@@ -181,7 +183,7 @@ export interface AppendFileOptions {
path: string;
/**
- * The data to write
+ * The data to append
*
* @since 1.0.0
*/
@@ -195,8 +197,10 @@ export interface AppendFileOptions {
directory?: Directory;
/**
- * The encoding to write the file in. If not provided, data
- * is written as base64 encoded.
+ * The encoding to append to the file.
+ * If not provided, binary data will be appended. For this, you must provide data as base64 encoded,
+ * so that the plugin can decode it before writing to disk.
+ * If you do not provide encoding and use non-base64 data, an error will be thrown.
*
* Pass Encoding.UTF8 to write data as string
*