#tauri-plugin #ios #workaround #directory #path #access

sys tauri-plugin-fs-ios

A plugin for accessing the filesystem on ios

4 releases (breaking)

new 0.4.0 Feb 13, 2025
0.3.0 Jan 2, 2025
0.2.0 Nov 19, 2024
0.1.0 Nov 19, 2024

#657 in Filesystem

MIT license

29KB
673 lines

Tauri Plugin fs-ios

Introduction

This is a temporarily workaround for interacting with the filesystem on iOS using tauri. It only allows access to the application's Documents directory under the app's bundle name.

Installation

  1. Install the npm package on the front-end
npm install tauri-plugin-fs-ios-api
  1. Install the cargo crate on in the src-tauri/ crate
cargo install tauri-plugin-fs-ios 
  1. Add init logic to lib.rs file

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    tauri::Builder::default()
        .plugin(tauri_plugin_fs_ios::init())
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

Usage

Create a file

import { createFile } from 'tauri-plugin-fs-ios-api'

const test_create_file = async(path: string, contents: string) => {

	return await createFile(path, contents)
}

Read a file

import { readFile } from 'tauri-plugin-fs-ios-api'

const test_read_file = async(path: string) => {

    return await readFile(path, "");
}

Write a file

import { writeFile } from 'tauri-plugin-fs-ios-api'

const test_write_file = async(path: string, contents: string) => {

	// overwrites previous contents of file
    return await writeFile(path, contents);
}

Append to a file

import { appendToFile } from 'tauri-plugin-fs-ios-api'

const test_appending_to_file = async(path: string, contents: string) => {

	// appends to previous contents of file
    return await appendToFile(path, contents);
}

Delete a file

import { deleteFile } from 'tauri-plugin-fs-ios-api'

const test_delete_file = async(path: string) => {

    return await deleteFile(path, "");
}

Create a Directory

import { createDir } from 'tauri-plugin-fs-ios-api'

const test_create_directory = async(path: string) => {

    return await deleteFile(path, "");
}

List Contents of Current Directory

import { listDir } from 'tauri-plugin-fs-ios-api'

const test_list_directory = async() => {

	// lists files and folders in current directory
    return await listDir("", "");
}

Print current Path

import { currentDir } from 'tauri-plugin-fs-ios-api'

const test_printing_directory = async() => {

	// returns current path
    return await currentDir("", "");
}

Delete a directory

import { deleteDir } from 'tauri-plugin-fs-ios-api'

const test_deleting_directory = async(path: string) => {

    return await deleteDir(path, "");
}

Rename a directory

import { renameDir } from 'tauri-plugin-fs-ios-api'

const test_renaming_directory = async(oldDir: string, newDir: string) => {

    return await renameDir(oldDir, newDir);
}

Dependencies

~17–57MB
~848K SLoC