Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tauri-apps/plugin-fs

Package Overview
Dependencies
Maintainers
0
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tauri-apps/plugin-fs - npm Package Compare versions

Comparing version 2.0.0-rc.0 to 2.0.0-rc.1

106

dist-js/index.d.ts

@@ -6,6 +6,6 @@ /**

*
* This module prevents path traversal, not allowing absolute paths or parent dir components
* (i.e. "/usr/path/to/file" or "../path/to/file" paths are not allowed).
* Paths accessed with this API must be relative to one of the {@link BaseDirectory | base directories}
* so if you need access to arbitrary filesystem paths, you must write such logic on the core layer instead.
* This module prevents path traversal, not allowing parent directory accessors to be used
* (i.e. "/usr/path/to/../file" or "../path/to/file" paths are not allowed).
* Paths accessed with this API must be either relative to one of the {@link BaseDirectory | base directories}
* or created with the {@link https://v2.tauri.app/reference/javascript/api/namespacepath | path API}.
*

@@ -32,3 +32,3 @@ * The API has a scope configuration that forces you to restrict the paths that can be accessed using glob patterns.

* {@linkcode https://v2.tauri.app/reference/javascript/api/namespacepath/#appdatadir | $APPDATA},
* {@linkcode https://v2.tauri.app/reference/javascript/api/namespacepath/#appLocaldatadir | $APPLOCALDATA},
* {@linkcode https://v2.tauri.app/reference/javascript/api/namespacepath/#applocaldatadir | $APPLOCALDATA},
* {@linkcode https://v2.tauri.app/reference/javascript/api/namespacepath/#appcachedir | $APPCACHE},

@@ -223,9 +223,9 @@ * {@linkcode https://v2.tauri.app/reference/javascript/api/namespacepath/#applogdir | $APPLOG},

* ```typescript
* import { open, read, close, BaseDirectory } from "@tauri-apps/plugin-fs"
* import { open, BaseDirectory } from "@tauri-apps/plugin-fs"
* // if "$APP/foo/bar.txt" contains the text "hello world":
* const file = await open("foo/bar.txt", { baseDir: BaseDirectory.App });
* const file = await open("foo/bar.txt", { baseDir: BaseDirectory.AppConfig });
* const buf = new Uint8Array(100);
* const numberOfBytesRead = await file.read(buf); // 11 bytes
* const text = new TextDecoder().decode(buf); // "hello world"
* await close(file.rid);
* await file.close();
* ```

@@ -250,7 +250,7 @@ *

* ```typescript
* import { open, seek, write, SeekMode, BaseDirectory } from '@tauri-apps/plugin-fs';
* import { open, SeekMode, BaseDirectory } from '@tauri-apps/plugin-fs';
*
* // Given hello.txt pointing to file with "Hello world", which is 11 bytes long:
* const file = await open('hello.txt', { read: true, write: true, truncate: true, create: true, baseDir: BaseDirectory.App });
* await file.write(new TextEncoder().encode("Hello world"), { baseDir: BaseDirectory.App });
* const file = await open('hello.txt', { read: true, write: true, truncate: true, create: true, baseDir: BaseDirectory.AppLocalData });
* await file.write(new TextEncoder().encode("Hello world"));
*

@@ -263,2 +263,4 @@ * // Seek 6 bytes from the start of the file

* console.log(await file.seek(-2, SeekMode.End)); // "9" (e.g. 11-2)
*
* await file.close();
* ```

@@ -274,6 +276,7 @@ *

* ```typescript
* import { open, fstat, BaseDirectory } from '@tauri-apps/plugin-fs';
* const file = await open("file.txt", { read: true, baseDir: BaseDirectory.App });
* const fileInfo = await fstat(file.rid);
* import { open, BaseDirectory } from '@tauri-apps/plugin-fs';
* const file = await open("file.txt", { read: true, baseDir: BaseDirectory.AppLocalData });
* const fileInfo = await file.stat();
* console.log(fileInfo.isFile); // true
* await file.close();
* ```

@@ -290,15 +293,16 @@ *

* ```typescript
* import { ftruncate, open, write, read, BaseDirectory } from '@tauri-apps/plugin-fs';
* import { open, BaseDirectory } from '@tauri-apps/plugin-fs';
*
* // truncate the entire file
* const file = await open("my_file.txt", { read: true, write: true, create: true, baseDir: BaseDirectory.App });
* await ftruncate(file.rid);
* const file = await open("my_file.txt", { read: true, write: true, create: true, baseDir: BaseDirectory.AppLocalData });
* await file.truncate();
*
* // truncate part of the file
* const file = await open("my_file.txt", { read: true, write: true, create: true, baseDir: BaseDirectory.App });
* await write(file.rid, new TextEncoder().encode("Hello World"));
* await ftruncate(file.rid, 7);
* const file = await open("my_file.txt", { read: true, write: true, create: true, baseDir: BaseDirectory.AppLocalData });
* await file.write(new TextEncoder().encode("Hello World"));
* await file.truncate(7);
* const data = new Uint8Array(32);
* await read(file.rid, data);
* await file.read(data);
* console.log(new TextDecoder().decode(data)); // Hello W
* await file.close();
* ```

@@ -319,8 +323,8 @@ *

* ```typescript
* import { open, write, close, BaseDirectory } from '@tauri-apps/plugin-fs';
* import { open, write, BaseDirectory } from '@tauri-apps/plugin-fs';
* const encoder = new TextEncoder();
* const data = encoder.encode("Hello world");
* const file = await open("bar.txt", { write: true, baseDir: BaseDirectory.App });
* const bytesWritten = await write(file.rid, data); // 11
* await close(file.rid);
* const file = await open("bar.txt", { write: true, baseDir: BaseDirectory.AppLocalData });
* const bytesWritten = await file.write(data); // 11
* await file.close();
* ```

@@ -346,3 +350,5 @@ *

* import { create, BaseDirectory } from "@tauri-apps/plugin-fs"
* const file = await create("foo/bar.txt", { baseDir: BaseDirectory.App });
* const file = await create("foo/bar.txt", { baseDir: BaseDirectory.AppConfig });
* await file.write(new TextEncoder().encode("Hello world"));
* await file.close();
* ```

@@ -414,5 +420,5 @@ *

* import { open, BaseDirectory } from "@tauri-apps/plugin-fs"
* const file = await open("foo/bar.txt", { read: true, write: true, baseDir: BaseDirectory.App });
* const file = await open("foo/bar.txt", { read: true, write: true, baseDir: BaseDirectory.AppLocalData });
* // Do work with file
* await close(file.rid);
* await file.close();
* ```

@@ -437,3 +443,3 @@ *

* import { copyFile, BaseDirectory } from '@tauri-apps/plugin-fs';
* await copyFile('app.conf', 'app.conf.bk', { fromPathBaseDir: BaseDirectory.App, toPathBaseDir: BaseDirectory.App });
* await copyFile('app.conf', 'app.conf.bk', { fromPathBaseDir: BaseDirectory.AppConfig, toPathBaseDir: BaseDirectory.AppConfig });
* ```

@@ -462,3 +468,3 @@ *

* import { mkdir, BaseDirectory } from '@tauri-apps/plugin-fs';
* await mkdir('users', { baseDir: BaseDirectory.App });
* await mkdir('users', { baseDir: BaseDirectory.AppLocalData });
* ```

@@ -500,5 +506,5 @@ *

* const dir = "users"
* const entries = await readDir('users', { baseDir: BaseDirectory.App });
* processEntriesRecursive(dir, entries);
* async function processEntriesRecursive(parent, entries) {
* const entries = await readDir('users', { baseDir: BaseDirectory.AppLocalData });
* processEntriesRecursively(dir, entries);
* async function processEntriesRecursively(parent, entries) {
* for (const entry of entries) {

@@ -508,3 +514,3 @@ * console.log(`Entry: ${entry.name}`);

* const dir = await join(parent, entry.name);
* processEntriesRecursive(dir, await readDir(dir, { baseDir: BaseDirectory.App }))
* processEntriesRecursively(dir, await readDir(dir, { baseDir: BaseDirectory.AppLocalData }))
* }

@@ -542,3 +548,3 @@ * }

* import { readTextFile, BaseDirectory } from '@tauri-apps/plugin-fs';
* const contents = await readTextFile('app.conf', { baseDir: BaseDirectory.App });
* const contents = await readTextFile('app.conf', { baseDir: BaseDirectory.AppConfig });
* ```

@@ -554,3 +560,3 @@ *

* import { readTextFileLines, BaseDirectory } from '@tauri-apps/plugin-fs';
* const lines = await readTextFileLines('app.conf', { baseDir: BaseDirectory.App });
* const lines = await readTextFileLines('app.conf', { baseDir: BaseDirectory.AppConfig });
* for await (const line of lines) {

@@ -581,4 +587,4 @@ * console.log(line);

* import { remove, BaseDirectory } from '@tauri-apps/plugin-fs';
* await remove('users/file.txt', { baseDir: BaseDirectory.App });
* await remove('users', { baseDir: BaseDirectory.App });
* await remove('users/file.txt', { baseDir: BaseDirectory.AppLocalData });
* await remove('users', { baseDir: BaseDirectory.AppLocalData });
* ```

@@ -608,3 +614,3 @@ *

* import { rename, BaseDirectory } from '@tauri-apps/plugin-fs';
* await rename('avatar.png', 'deleted.png', { oldPathBaseDir: BaseDirectory.App, newPathBaseDir: BaseDirectory.App });
* await rename('avatar.png', 'deleted.png', { oldPathBaseDir: BaseDirectory.App, newPathBaseDir: BaseDirectory.AppLocalData });
* ```

@@ -629,3 +635,3 @@ *

* import { stat, BaseDirectory } from '@tauri-apps/plugin-fs';
* const fileInfo = await stat("hello.txt", { baseDir: BaseDirectory.App });
* const fileInfo = await stat("hello.txt", { baseDir: BaseDirectory.AppLocalData });
* console.log(fileInfo.isFile); // true

@@ -645,3 +651,3 @@ * ```

* import { lstat, BaseDirectory } from '@tauri-apps/plugin-fs';
* const fileInfo = await lstat("hello.txt", { baseDir: BaseDirectory.App });
* const fileInfo = await lstat("hello.txt", { baseDir: BaseDirectory.AppLocalData });
* console.log(fileInfo.isFile); // true

@@ -666,12 +672,12 @@ * ```

* ```typescript
* import { truncate, readFile, writeFile, BaseDirectory } from '@tauri-apps/plugin-fs';
* import { truncate, readTextFile, writeTextFile, BaseDirectory } from '@tauri-apps/plugin-fs';
* // truncate the entire file
* await truncate("my_file.txt", 0, { baseDir: BaseDirectory.App });
* await truncate("my_file.txt", 0, { baseDir: BaseDirectory.AppLocalData });
*
* // truncate part of the file
* let file = "file.txt";
* await writeFile(file, new TextEncoder().encode("Hello World"), { baseDir: BaseDirectory.App });
* await truncate(file, 7);
* const data = await readFile(file, { baseDir: BaseDirectory.App });
* console.log(new TextDecoder().decode(data)); // "Hello W"
* const filePath = "file.txt";
* await writeTextFile(filePath, "Hello World", { baseDir: BaseDirectory.AppLocalData });
* await truncate(filePath, 7, { baseDir: BaseDirectory.AppLocalData });
* const data = await readTextFile(filePath, { baseDir: BaseDirectory.AppLocalData });
* console.log(data); // "Hello W"
* ```

@@ -705,3 +711,3 @@ *

* let data = encoder.encode("Hello World");
* await writeFile('file.txt', data, { baseDir: BaseDirectory.App });
* await writeFile('file.txt', data, { baseDir: BaseDirectory.AppLocalData });
* ```

@@ -718,3 +724,3 @@ *

*
* await writeTextFile('file.txt', "Hello world", { baseDir: BaseDirectory.App });
* await writeTextFile('file.txt', "Hello world", { baseDir: BaseDirectory.AppLocalData });
* ```

@@ -721,0 +727,0 @@ *

@@ -12,6 +12,6 @@ export { BaseDirectory } from '@tauri-apps/api/path';

*
* This module prevents path traversal, not allowing absolute paths or parent dir components
* (i.e. "/usr/path/to/file" or "../path/to/file" paths are not allowed).
* Paths accessed with this API must be relative to one of the {@link BaseDirectory | base directories}
* so if you need access to arbitrary filesystem paths, you must write such logic on the core layer instead.
* This module prevents path traversal, not allowing parent directory accessors to be used
* (i.e. "/usr/path/to/../file" or "../path/to/file" paths are not allowed).
* Paths accessed with this API must be either relative to one of the {@link BaseDirectory | base directories}
* or created with the {@link https://v2.tauri.app/reference/javascript/api/namespacepath | path API}.
*

@@ -38,3 +38,3 @@ * The API has a scope configuration that forces you to restrict the paths that can be accessed using glob patterns.

* {@linkcode https://v2.tauri.app/reference/javascript/api/namespacepath/#appdatadir | $APPDATA},
* {@linkcode https://v2.tauri.app/reference/javascript/api/namespacepath/#appLocaldatadir | $APPLOCALDATA},
* {@linkcode https://v2.tauri.app/reference/javascript/api/namespacepath/#applocaldatadir | $APPLOCALDATA},
* {@linkcode https://v2.tauri.app/reference/javascript/api/namespacepath/#appcachedir | $APPCACHE},

@@ -121,9 +121,9 @@ * {@linkcode https://v2.tauri.app/reference/javascript/api/namespacepath/#applogdir | $APPLOG},

* ```typescript
* import { open, read, close, BaseDirectory } from "@tauri-apps/plugin-fs"
* import { open, BaseDirectory } from "@tauri-apps/plugin-fs"
* // if "$APP/foo/bar.txt" contains the text "hello world":
* const file = await open("foo/bar.txt", { baseDir: BaseDirectory.App });
* const file = await open("foo/bar.txt", { baseDir: BaseDirectory.AppConfig });
* const buf = new Uint8Array(100);
* const numberOfBytesRead = await file.read(buf); // 11 bytes
* const text = new TextDecoder().decode(buf); // "hello world"
* await close(file.rid);
* await file.close();
* ```

@@ -158,7 +158,7 @@ *

* ```typescript
* import { open, seek, write, SeekMode, BaseDirectory } from '@tauri-apps/plugin-fs';
* import { open, SeekMode, BaseDirectory } from '@tauri-apps/plugin-fs';
*
* // Given hello.txt pointing to file with "Hello world", which is 11 bytes long:
* const file = await open('hello.txt', { read: true, write: true, truncate: true, create: true, baseDir: BaseDirectory.App });
* await file.write(new TextEncoder().encode("Hello world"), { baseDir: BaseDirectory.App });
* const file = await open('hello.txt', { read: true, write: true, truncate: true, create: true, baseDir: BaseDirectory.AppLocalData });
* await file.write(new TextEncoder().encode("Hello world"));
*

@@ -171,2 +171,4 @@ * // Seek 6 bytes from the start of the file

* console.log(await file.seek(-2, SeekMode.End)); // "9" (e.g. 11-2)
*
* await file.close();
* ```

@@ -188,6 +190,7 @@ *

* ```typescript
* import { open, fstat, BaseDirectory } from '@tauri-apps/plugin-fs';
* const file = await open("file.txt", { read: true, baseDir: BaseDirectory.App });
* const fileInfo = await fstat(file.rid);
* import { open, BaseDirectory } from '@tauri-apps/plugin-fs';
* const file = await open("file.txt", { read: true, baseDir: BaseDirectory.AppLocalData });
* const fileInfo = await file.stat();
* console.log(fileInfo.isFile); // true
* await file.close();
* ```

@@ -209,15 +212,16 @@ *

* ```typescript
* import { ftruncate, open, write, read, BaseDirectory } from '@tauri-apps/plugin-fs';
* import { open, BaseDirectory } from '@tauri-apps/plugin-fs';
*
* // truncate the entire file
* const file = await open("my_file.txt", { read: true, write: true, create: true, baseDir: BaseDirectory.App });
* await ftruncate(file.rid);
* const file = await open("my_file.txt", { read: true, write: true, create: true, baseDir: BaseDirectory.AppLocalData });
* await file.truncate();
*
* // truncate part of the file
* const file = await open("my_file.txt", { read: true, write: true, create: true, baseDir: BaseDirectory.App });
* await write(file.rid, new TextEncoder().encode("Hello World"));
* await ftruncate(file.rid, 7);
* const file = await open("my_file.txt", { read: true, write: true, create: true, baseDir: BaseDirectory.AppLocalData });
* await file.write(new TextEncoder().encode("Hello World"));
* await file.truncate(7);
* const data = new Uint8Array(32);
* await read(file.rid, data);
* await file.read(data);
* console.log(new TextDecoder().decode(data)); // Hello W
* await file.close();
* ```

@@ -243,8 +247,8 @@ *

* ```typescript
* import { open, write, close, BaseDirectory } from '@tauri-apps/plugin-fs';
* import { open, write, BaseDirectory } from '@tauri-apps/plugin-fs';
* const encoder = new TextEncoder();
* const data = encoder.encode("Hello world");
* const file = await open("bar.txt", { write: true, baseDir: BaseDirectory.App });
* const bytesWritten = await write(file.rid, data); // 11
* await close(file.rid);
* const file = await open("bar.txt", { write: true, baseDir: BaseDirectory.AppLocalData });
* const bytesWritten = await file.write(data); // 11
* await file.close();
* ```

@@ -268,3 +272,5 @@ *

* import { create, BaseDirectory } from "@tauri-apps/plugin-fs"
* const file = await create("foo/bar.txt", { baseDir: BaseDirectory.App });
* const file = await create("foo/bar.txt", { baseDir: BaseDirectory.AppConfig });
* await file.write(new TextEncoder().encode("Hello world"));
* await file.close();
* ```

@@ -293,5 +299,5 @@ *

* import { open, BaseDirectory } from "@tauri-apps/plugin-fs"
* const file = await open("foo/bar.txt", { read: true, write: true, baseDir: BaseDirectory.App });
* const file = await open("foo/bar.txt", { read: true, write: true, baseDir: BaseDirectory.AppLocalData });
* // Do work with file
* await close(file.rid);
* await file.close();
* ```

@@ -316,3 +322,3 @@ *

* import { copyFile, BaseDirectory } from '@tauri-apps/plugin-fs';
* await copyFile('app.conf', 'app.conf.bk', { fromPathBaseDir: BaseDirectory.App, toPathBaseDir: BaseDirectory.App });
* await copyFile('app.conf', 'app.conf.bk', { fromPathBaseDir: BaseDirectory.AppConfig, toPathBaseDir: BaseDirectory.AppConfig });
* ```

@@ -338,3 +344,3 @@ *

* import { mkdir, BaseDirectory } from '@tauri-apps/plugin-fs';
* await mkdir('users', { baseDir: BaseDirectory.App });
* await mkdir('users', { baseDir: BaseDirectory.AppLocalData });
* ```

@@ -360,5 +366,5 @@ *

* const dir = "users"
* const entries = await readDir('users', { baseDir: BaseDirectory.App });
* processEntriesRecursive(dir, entries);
* async function processEntriesRecursive(parent, entries) {
* const entries = await readDir('users', { baseDir: BaseDirectory.AppLocalData });
* processEntriesRecursively(dir, entries);
* async function processEntriesRecursively(parent, entries) {
* for (const entry of entries) {

@@ -368,3 +374,3 @@ * console.log(`Entry: ${entry.name}`);

* const dir = await join(parent, entry.name);
* processEntriesRecursive(dir, await readDir(dir, { baseDir: BaseDirectory.App }))
* processEntriesRecursively(dir, await readDir(dir, { baseDir: BaseDirectory.AppLocalData }))
* }

@@ -414,3 +420,3 @@ * }

* import { readTextFile, BaseDirectory } from '@tauri-apps/plugin-fs';
* const contents = await readTextFile('app.conf', { baseDir: BaseDirectory.App });
* const contents = await readTextFile('app.conf', { baseDir: BaseDirectory.AppConfig });
* ```

@@ -434,3 +440,3 @@ *

* import { readTextFileLines, BaseDirectory } from '@tauri-apps/plugin-fs';
* const lines = await readTextFileLines('app.conf', { baseDir: BaseDirectory.App });
* const lines = await readTextFileLines('app.conf', { baseDir: BaseDirectory.AppConfig });
* for await (const line of lines) {

@@ -480,4 +486,4 @@ * console.log(line);

* import { remove, BaseDirectory } from '@tauri-apps/plugin-fs';
* await remove('users/file.txt', { baseDir: BaseDirectory.App });
* await remove('users', { baseDir: BaseDirectory.App });
* await remove('users/file.txt', { baseDir: BaseDirectory.AppLocalData });
* await remove('users', { baseDir: BaseDirectory.AppLocalData });
* ```

@@ -506,3 +512,3 @@ *

* import { rename, BaseDirectory } from '@tauri-apps/plugin-fs';
* await rename('avatar.png', 'deleted.png', { oldPathBaseDir: BaseDirectory.App, newPathBaseDir: BaseDirectory.App });
* await rename('avatar.png', 'deleted.png', { oldPathBaseDir: BaseDirectory.App, newPathBaseDir: BaseDirectory.AppLocalData });
* ```

@@ -530,3 +536,3 @@ *

* import { stat, BaseDirectory } from '@tauri-apps/plugin-fs';
* const fileInfo = await stat("hello.txt", { baseDir: BaseDirectory.App });
* const fileInfo = await stat("hello.txt", { baseDir: BaseDirectory.AppLocalData });
* console.log(fileInfo.isFile); // true

@@ -552,3 +558,3 @@ * ```

* import { lstat, BaseDirectory } from '@tauri-apps/plugin-fs';
* const fileInfo = await lstat("hello.txt", { baseDir: BaseDirectory.App });
* const fileInfo = await lstat("hello.txt", { baseDir: BaseDirectory.AppLocalData });
* console.log(fileInfo.isFile); // true

@@ -572,12 +578,12 @@ * ```

* ```typescript
* import { truncate, readFile, writeFile, BaseDirectory } from '@tauri-apps/plugin-fs';
* import { truncate, readTextFile, writeTextFile, BaseDirectory } from '@tauri-apps/plugin-fs';
* // truncate the entire file
* await truncate("my_file.txt", 0, { baseDir: BaseDirectory.App });
* await truncate("my_file.txt", 0, { baseDir: BaseDirectory.AppLocalData });
*
* // truncate part of the file
* let file = "file.txt";
* await writeFile(file, new TextEncoder().encode("Hello World"), { baseDir: BaseDirectory.App });
* await truncate(file, 7);
* const data = await readFile(file, { baseDir: BaseDirectory.App });
* console.log(new TextDecoder().decode(data)); // "Hello W"
* const filePath = "file.txt";
* await writeTextFile(filePath, "Hello World", { baseDir: BaseDirectory.AppLocalData });
* await truncate(filePath, 7, { baseDir: BaseDirectory.AppLocalData });
* const data = await readTextFile(filePath, { baseDir: BaseDirectory.AppLocalData });
* console.log(data); // "Hello W"
* ```

@@ -605,3 +611,3 @@ *

* let data = encoder.encode("Hello World");
* await writeFile('file.txt', data, { baseDir: BaseDirectory.App });
* await writeFile('file.txt', data, { baseDir: BaseDirectory.AppLocalData });
* ```

@@ -628,3 +634,3 @@ *

*
* await writeTextFile('file.txt', "Hello world", { baseDir: BaseDirectory.App });
* await writeTextFile('file.txt', "Hello world", { baseDir: BaseDirectory.AppLocalData });
* ```

@@ -631,0 +637,0 @@ *

{
"name": "@tauri-apps/plugin-fs",
"version": "2.0.0-rc.0",
"version": "2.0.0-rc.1",
"description": "Access the file system.",

@@ -28,4 +28,4 @@ "license": "MIT or APACHE-2.0",

"dependencies": {
"@tauri-apps/api": "^2.0.0-rc.0"
"@tauri-apps/api": "^2.0.0-rc.1"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc