Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/capacitor-plugin/CapacitorFilesystem.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ Pod::Spec.new do |s|
]
s.ios.deployment_target = '15.0'
s.dependency 'Capacitor'
s.dependency 'IONFilesystemLib', spec='~> 1.0.1'
s.dependency 'IONFilesystemLib', spec='~> 1.1.0'
s.swift_version = '5.1'
end
2 changes: 1 addition & 1 deletion packages/capacitor-plugin/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0"),
.package(url: "https://github.com/ionic-team/ion-ios-filesystem.git", from: "1.0.1")
.package(url: "https://github.com/ionic-team/ion-ios-filesystem.git", from: "1.1.0")
],
targets: [
.target(
Expand Down
12 changes: 7 additions & 5 deletions packages/capacitor-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,13 @@ We recommend using the @capacitor/file-transfer plugin instead, in conjunction w

#### ReadFileOptions

| Prop | Type | Description | Since |
| --------------- | ----------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`path`** | <code>string</code> | The path of the file to read | 1.0.0 |
| **`directory`** | <code><a href="#directory">Directory</a></code> | The <a href="#directory">`Directory`</a> to read the file from | 1.0.0 |
| **`encoding`** | <code><a href="#encoding">Encoding</a></code> | The encoding to read the file in, if not provided, data is read as binary and returned as base64 encoded. Pass <a href="#encoding">Encoding.UTF8</a> to read data as string | 1.0.0 |
| Prop | Type | Description | Default | Since |
| --------------- | ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------- | ----- |
| **`path`** | <code>string</code> | The path of the file to read | | 1.0.0 |
| **`directory`** | <code><a href="#directory">Directory</a></code> | The <a href="#directory">`Directory`</a> to read the file from | | 1.0.0 |
| **`encoding`** | <code><a href="#encoding">Encoding</a></code> | The encoding to read the file in, if not provided, data is read as binary and returned as base64 encoded. Pass <a href="#encoding">Encoding.UTF8</a> to read data as string | | 1.0.0 |
| **`offset`** | <code>number</code> | The offset to start reading the file from, in bytes. Native only (not available in web). Can be used in conjunction with length to partially read files. | <code>0</code> | 8.1.0 |
| **`length`** | <code>number</code> | The length of data to read, in bytes. Any non-positive value means to read to the end of the file. Native only (not available in web). Can be used in conjunction with offset to partially read files. | <code>-1</code> | 8.1.0 |


#### ReadFileInChunksOptions
Expand Down
2 changes: 1 addition & 1 deletion packages/capacitor-plugin/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ repositories {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "io.ionic.libs:ionfilesystem-android:1.0.0"
implementation "io.ionic.libs:ionfilesystem-android:1.1.0"
implementation project(':capacitor-android')
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,7 @@ fun Throwable.toFilesystemError(methodName: String): FilesystemErrors.ErrorInfo
is IONFILEExceptions.CopyRenameFailed.NoParentDirectory ->
FilesystemErrors.missingParentDirectories

is IllegalArgumentException -> FilesystemErrors.invalidInputMethod(methodName)

else -> FilesystemErrors.operationFailed(methodName, this.localizedMessage ?: "")
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.capacitorjs.plugins.filesystem

import com.getcapacitor.PluginCall
import io.ionic.libs.ionfilesystemlib.model.IONFILEConstants
import io.ionic.libs.ionfilesystemlib.model.IONFILEEncoding
import io.ionic.libs.ionfilesystemlib.model.IONFILEFolderType
import io.ionic.libs.ionfilesystemlib.model.IONFILEReadInChunksOptions
Expand All @@ -13,6 +14,8 @@ internal const val INPUT_APPEND = "append"
private const val INPUT_PATH = "path"
private const val INPUT_DIRECTORY = "directory"
private const val INPUT_ENCODING = "encoding"
private const val INPUT_OFFSET = "offset"
private const val INPUT_LENGTH = "length"
private const val INPUT_CHUNK_SIZE = "chunkSize"
private const val INPUT_DATA = "data"
private const val INPUT_RECURSIVE = "recursive"
Expand Down Expand Up @@ -52,7 +55,15 @@ internal data class DoubleUri(
internal fun PluginCall.getReadFileOptions(): ReadFileOptions? {
val uri = getSingleIONFILEUri() ?: return null
val encoding = IONFILEEncoding.fromEncodingName(getString(INPUT_ENCODING))
return ReadFileOptions(uri = uri, options = IONFILEReadOptions(encoding))
val offsetAndLength = getOffsetAndLength()
return ReadFileOptions(
uri = uri,
options = IONFILEReadOptions(
encoding,
offset = offsetAndLength.first,
length = offsetAndLength.second
)
)
}

/**
Expand All @@ -62,9 +73,15 @@ internal fun PluginCall.getReadFileInChunksOptions(): ReadFileInChunksOptions? {
val uri = getSingleIONFILEUri() ?: return null
val encoding = IONFILEEncoding.fromEncodingName(getString(INPUT_ENCODING))
val chunkSize = getInt(INPUT_CHUNK_SIZE)?.takeIf { it > 0 } ?: return null
val offsetAndLength = getOffsetAndLength()
return ReadFileInChunksOptions(
uri = uri,
options = IONFILEReadInChunksOptions(encoding, chunkSize)
options = IONFILEReadInChunksOptions(
encoding,
chunkSize = chunkSize,
offset = offsetAndLength.first,
length = offsetAndLength.second
)
)
}

Expand Down Expand Up @@ -123,6 +140,11 @@ internal fun PluginCall.getSingleIONFILEUri(): IONFILEUri.Unresolved? {
return unresolvedUri(path, directoryAlias)
}

private fun PluginCall.getOffsetAndLength(): Pair<Int, Int> = Pair(
getInt(INPUT_OFFSET)?.takeIf { it >= 0 } ?: 0,
getInt(INPUT_LENGTH)?.takeIf { it > 0 } ?: IONFILEConstants.LENGTH_READ_TIL_EOF
)

private fun unresolvedUri(path: String, directoryAlias: String?) = IONFILEUri.Unresolved(
parentFolder = IONFILEFolderType.fromStringAlias(directoryAlias),
uriPath = path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ struct Constants {
static let directory = "directory"
static let encoding = "encoding"
static let chunkSize = "chunkSize"
static let offset = "offset"
static let length = "length"
static let from = "from"
static let path = "path"
static let recursive = "recursive"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import IONFilesystemLib

enum FilesystemOperation {
// Read Operations
case readFile(url: URL, encoding: IONFILEEncoding)
case readFileInChunks(url: URL, encoding: IONFILEEncoding, chunkSize: Int)
case readFile(url: URL, encoding: IONFILEEncoding, offset: Int, length: Int)
case readFileInChunks(url: URL, encoding: IONFILEEncoding, chunkSize: Int, offset: Int, length: Int)
case readdir(url: URL)
case stat(url: URL)
case getUri(url: URL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class FilesystemOperationExecutor {
var resultData: PluginCallResultData?

switch operation {
case .readFile(let url, let encoding):
let data = try service.readEntireFile(atURL: url, withEncoding: encoding).textValue
case .readFile(let url, let encoding, let offset, let length):
let data = try service.readEntireFile(atURL: url, withEncoding: encoding, andOffset: offset, andLength: length).textValue
resultData = [Constants.ResultDataKey.data: data]
case .readFileInChunks(let url, let encoding, let chunkSize):
try processFileInChunks(at: url, withEncoding: encoding, chunkSize: chunkSize, for: operation, call)
case .readFileInChunks(let url, let encoding, let chunkSize, let offset, let length):
try processFileInChunks(at: url, withEncoding: encoding, chunkSize: chunkSize, offset: offset, length: length, for: operation, call)
return
case .write(let url, let encodingMapper, let recursive):
try service.saveFile(atURL: url, withEncodingAndData: encodingMapper, includeIntermediateDirectories: recursive)
Expand Down Expand Up @@ -56,9 +56,9 @@ class FilesystemOperationExecutor {
}

private extension FilesystemOperationExecutor {
func processFileInChunks(at url: URL, withEncoding encoding: IONFILEEncoding, chunkSize: Int, for operation: FilesystemOperation, _ call: CAPPluginCall) throws {
func processFileInChunks(at url: URL, withEncoding encoding: IONFILEEncoding, chunkSize: Int, offset: Int, length: Int, for operation: FilesystemOperation, _ call: CAPPluginCall) throws {
let chunkSizeToUse = chunkSizeToUse(basedOn: chunkSize, and: encoding)
try service.readFileInChunks(atURL: url, withEncoding: encoding, andChunkSize: chunkSizeToUse)
try service.readFileInChunks(atURL: url, withEncoding: encoding, andChunkSize: chunkSizeToUse, andOffset: offset, andLength: length)
.sink(receiveCompletion: { completion in
switch completion {
case .finished:
Expand All @@ -82,8 +82,8 @@ private extension FilesystemOperationExecutor {
var path = ""
var method: IONFileMethod = IONFileMethod.getUri
switch operation {
case .readFile(let url, _): path = url.absoluteString; method = .readFile
case .readFileInChunks(let url, _, _): path = url.absoluteString; method = .readFileInChunks
case .readFile(let url, _, _, _): path = url.absoluteString; method = .readFile
case .readFileInChunks(let url, _, _, _, _): path = url.absoluteString; method = .readFileInChunks
case .write(let url, _, _): path = url.absoluteString; method = .writeFile
case .append(let url, _, _): path = url.absoluteString; method = .appendFile
case .delete(let url): path = url.absoluteString; method = .deleteFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ private extension FilesystemPlugin {
*/
@objc func readFile(_ call: CAPPluginCall) {
let encoding = call.getEncoding(Constants.MethodParameter.encoding)
let offset = call.getInt(Constants.MethodParameter.offset) ?? 0
let length = call.getInt(Constants.MethodParameter.length) ?? -1
performSinglePathOperation(call) {
.readFile(url: $0, encoding: encoding)
.readFile(url: $0, encoding: encoding, offset: offset, length: length)
}
}

Expand All @@ -69,8 +71,10 @@ private extension FilesystemPlugin {
guard let chunkSize = call.getInt(Constants.MethodParameter.chunkSize) else {
return call.handleError(.invalidInput(method: call.getIONFileMethod()))
}
let offset = call.getInt(Constants.MethodParameter.offset) ?? 0
let length = call.getInt(Constants.MethodParameter.length) ?? -1
performSinglePathOperation(call) {
.readFileInChunks(url: $0, encoding: encoding, chunkSize: chunkSize)
.readFileInChunks(url: $0, encoding: encoding, chunkSize: chunkSize, offset: offset, length: length)
}
}

Expand Down
21 changes: 21 additions & 0 deletions packages/capacitor-plugin/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,27 @@ export interface ReadFileOptions {
* @since 1.0.0
*/
encoding?: Encoding;

/**
* The offset to start reading the file from, in bytes.
* Native only (not available in web).
* Can be used in conjunction with length to partially read files.
*
* @since 8.1.0
* @default 0
*/
offset?: number;

/**
* The length of data to read, in bytes.
* Any non-positive value means to read to the end of the file.
* Native only (not available in web).
* Can be used in conjunction with offset to partially read files.
*
* @since 8.1.0
* @default -1
*/
length?: number;
}

export interface ReadFileInChunksOptions extends ReadFileOptions {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN
include ':capacitor-android'
project(':capacitor-android').projectDir = new File('../../../node_modules/.pnpm/@capacitor+android@8.0.0-beta.0_@capacitor+core@8.0.0-beta.0/node_modules/@capacitor/android/capacitor')
project(':capacitor-android').projectDir = new File('../node_modules/@capacitor/android/capacitor')

include ':capacitor-camera'
project(':capacitor-camera').projectDir = new File('../../../node_modules/.pnpm/@capacitor+camera@8.0.0-beta.0_@capacitor+core@8.0.0-beta.0/node_modules/@capacitor/camera/android')
project(':capacitor-camera').projectDir = new File('../node_modules/@capacitor/camera/android')

include ':capacitor-splash-screen'
project(':capacitor-splash-screen').projectDir = new File('../../../node_modules/.pnpm/@capacitor+splash-screen@8.0.0-beta.0_@capacitor+core@8.0.0-beta.0/node_modules/@capacitor/splash-screen/android')
project(':capacitor-splash-screen').projectDir = new File('../node_modules/@capacitor/splash-screen/android')

include ':capacitor-filesystem'
project(':capacitor-filesystem').projectDir = new File('../../capacitor-plugin/android')
10 changes: 5 additions & 5 deletions packages/example-app-capacitor/ios/App/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative '../../../../node_modules/.pnpm/@capacitor+ios@8.0.0-beta.0_@capacitor+core@8.0.0-beta.0/node_modules/@capacitor/ios/scripts/pods_helpers'
require_relative '../../node_modules/@capacitor/ios/scripts/pods_helpers'

platform :ios, '15.0'
use_frameworks!
Expand All @@ -9,10 +9,10 @@ use_frameworks!
install! 'cocoapods', :disable_input_output_paths => true

def capacitor_pods
pod 'Capacitor', :path => '../../../../node_modules/.pnpm/@capacitor+ios@8.0.0-beta.0_@capacitor+core@8.0.0-beta.0/node_modules/@capacitor/ios'
pod 'CapacitorCordova', :path => '../../../../node_modules/.pnpm/@capacitor+ios@8.0.0-beta.0_@capacitor+core@8.0.0-beta.0/node_modules/@capacitor/ios'
pod 'CapacitorCamera', :path => '../../../../node_modules/.pnpm/@capacitor+camera@8.0.0-beta.0_@capacitor+core@8.0.0-beta.0/node_modules/@capacitor/camera'
pod 'CapacitorSplashScreen', :path => '../../../../node_modules/.pnpm/@capacitor+splash-screen@8.0.0-beta.0_@capacitor+core@8.0.0-beta.0/node_modules/@capacitor/splash-screen'
pod 'Capacitor', :path => '../../node_modules/@capacitor/ios'
pod 'CapacitorCordova', :path => '../../node_modules/@capacitor/ios'
pod 'CapacitorCamera', :path => '../../node_modules/@capacitor/camera'
pod 'CapacitorSplashScreen', :path => '../../node_modules/@capacitor/splash-screen'
pod 'CapacitorFilesystem', :path => '../../../capacitor-plugin'
end

Expand Down
44 changes: 22 additions & 22 deletions packages/example-app-capacitor/ios/App/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
PODS:
- Capacitor (8.0.0-beta.0):
- Capacitor (8.0.1):
- CapacitorCordova
- CapacitorCamera (8.0.0-beta.0):
- CapacitorCamera (8.0.0):
- Capacitor
- CapacitorCordova (8.0.0-beta.0)
- CapacitorFilesystem (8.0.0-next.3):
- CapacitorCordova (8.0.1)
- CapacitorFilesystem (8.0.0):
- Capacitor
- IONFilesystemLib (~> 1.0.1)
- CapacitorSplashScreen (8.0.0-beta.0):
- IONFilesystemLib (~> 1.1.0)
- CapacitorSplashScreen (8.0.0):
- Capacitor
- IONFilesystemLib (1.0.1)
- IONFilesystemLib (1.1.0)

DEPENDENCIES:
- "Capacitor (from `../../../../node_modules/.pnpm/@capacitor+ios@8.0.0-beta.0_@capacitor+core@8.0.0-beta.0/node_modules/@capacitor/ios`)"
- "CapacitorCamera (from `../../../../node_modules/.pnpm/@capacitor+camera@8.0.0-beta.0_@capacitor+core@8.0.0-beta.0/node_modules/@capacitor/camera`)"
- "CapacitorCordova (from `../../../../node_modules/.pnpm/@capacitor+ios@8.0.0-beta.0_@capacitor+core@8.0.0-beta.0/node_modules/@capacitor/ios`)"
- "Capacitor (from `../../node_modules/@capacitor/ios`)"
- "CapacitorCamera (from `../../node_modules/@capacitor/camera`)"
- "CapacitorCordova (from `../../node_modules/@capacitor/ios`)"
- CapacitorFilesystem (from `../../../capacitor-plugin`)
- "CapacitorSplashScreen (from `../../../../node_modules/.pnpm/@capacitor+splash-screen@8.0.0-beta.0_@capacitor+core@8.0.0-beta.0/node_modules/@capacitor/splash-screen`)"
- "CapacitorSplashScreen (from `../../node_modules/@capacitor/splash-screen`)"

SPEC REPOS:
trunk:
- IONFilesystemLib

EXTERNAL SOURCES:
Capacitor:
:path: "../../../../node_modules/.pnpm/@capacitor+ios@8.0.0-beta.0_@capacitor+core@8.0.0-beta.0/node_modules/@capacitor/ios"
:path: "../../node_modules/@capacitor/ios"
CapacitorCamera:
:path: "../../../../node_modules/.pnpm/@capacitor+camera@8.0.0-beta.0_@capacitor+core@8.0.0-beta.0/node_modules/@capacitor/camera"
:path: "../../node_modules/@capacitor/camera"
CapacitorCordova:
:path: "../../../../node_modules/.pnpm/@capacitor+ios@8.0.0-beta.0_@capacitor+core@8.0.0-beta.0/node_modules/@capacitor/ios"
:path: "../../node_modules/@capacitor/ios"
CapacitorFilesystem:
:path: "../../../capacitor-plugin"
CapacitorSplashScreen:
:path: "../../../../node_modules/.pnpm/@capacitor+splash-screen@8.0.0-beta.0_@capacitor+core@8.0.0-beta.0/node_modules/@capacitor/splash-screen"
:path: "../../node_modules/@capacitor/splash-screen"

SPEC CHECKSUMS:
Capacitor: cdbe01d8f7b542b2750fb51e88051e764b3cbc4e
CapacitorCamera: 7ff9e46889cbd3bba2ed0a4192d40f91bd1b5f05
CapacitorCordova: 65a0b71358d76bdeb799f45cd0214d68fbe2fd56
CapacitorFilesystem: 744a5be26e8f658c60a149401dff136ede834bb8
CapacitorSplashScreen: ab1ec150884e35c67c7709c907b3db3a376b9956
IONFilesystemLib: 89258b8e3e85465da93127d25d7ce37f977e8a6f
Capacitor: ff35b0f66370b84aa238251b35b91886a3207c16
CapacitorCamera: 592acb7ab9fb748e2d8571eb03af30ec4e1ace12
CapacitorCordova: 0d65b9bb74e995dcecb9463f34f1af2aba6f955c
CapacitorFilesystem: c650a2b46e2bbeb4709aef2bcf0a44597e20158c
CapacitorSplashScreen: 422880d7117605c30699eb4b21644b62db42e86c
IONFilesystemLib: 50b9a0f3052a9b40b9bedb43f328a8fe222f9f87

PODFILE CHECKSUM: bcc6c8bf6cebbd15c772e65f0a0c65a41e700610
PODFILE CHECKSUM: f9801285586b6499bc9e372b1475a3f09f847217

COCOAPODS: 1.16.2
4 changes: 2 additions & 2 deletions packages/example-app-capacitor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
},
"dependencies": {
"@capacitor/android": "^8.0.0",
"@capacitor/camera": "^7.0.0 || ^8.0.0",
"@capacitor/camera": "^8.0.0",
"@capacitor/core": "^8.0.0",
"@capacitor/ios": "^8.0.0",
"@capacitor/splash-screen": "^7.0.0 || ^8.0.0",
"@capacitor/splash-screen": "^8.0.0",
"@capacitor/filesystem": "file:../capacitor-plugin"
},
"devDependencies": {
Expand Down
Loading
Loading