ltk/files/
callback.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// SPDX-License-Identifier: LGPL-2.1-only
// Copyright (C) 2026 Liberux Labs, S. L. <info@liberux.net>

//! The operations of [`crate::files`] with a function in place of a message, for code with no run loop's [`crate::ChannelSender`] to take one, such as a session daemon: `done` is called on ltk's worker thread natively and on the page's thread in a browser.

use std::io;
use std::path::PathBuf;

use super::{ backend, Entry, Metadata, Mount, Operation };

pub fn list( path: impl Into<PathBuf>, done: impl FnOnce( io::Result<Vec<Entry>> ) + Send + 'static )
{
	backend::list( path.into(), Box::new( done ) );
}

pub fn stat( path: impl Into<PathBuf>, done: impl FnOnce( io::Result<Metadata> ) + Send + 'static )
{
	backend::stat( path.into(), Box::new( done ) );
}

pub fn read( path: impl Into<PathBuf>, done: impl FnOnce( io::Result<Vec<u8>> ) + Send + 'static )
{
	backend::read( path.into(), None, Box::new( done ) );
}

pub fn read_range( path: impl Into<PathBuf>, offset: u64, length: u64, done: impl FnOnce( io::Result<Vec<u8>> ) + Send + 'static )
{
	backend::read( path.into(), Some( ( offset, length ) ), Box::new( done ) );
}

pub fn write( path: impl Into<PathBuf>, data: Vec<u8>, done: impl FnOnce( io::Result<()> ) + Send + 'static )
{
	backend::write( path.into(), data, Box::new( done ) );
}

pub fn create_dir( path: impl Into<PathBuf>, done: impl FnOnce( io::Result<()> ) + Send + 'static )
{
	backend::create_dir( path.into(), Box::new( done ) );
}

pub fn rename( from: impl Into<PathBuf>, to: impl Into<PathBuf>, done: impl FnOnce( io::Result<()> ) + Send + 'static )
{
	backend::rename( from.into(), to.into(), Box::new( done ) );
}

pub fn remove( path: impl Into<PathBuf>, done: impl FnOnce( io::Result<()> ) + Send + 'static )
{
	backend::remove( path.into(), false, Box::new( done ) );
}

pub fn remove_all( path: impl Into<PathBuf>, done: impl FnOnce( io::Result<()> ) + Send + 'static )
{
	backend::remove( path.into(), true, Box::new( done ) );
}

pub fn copy( from: impl Into<PathBuf>, to: impl Into<PathBuf>, progress: impl Fn( u64, u64 ) + Send + 'static, done: impl FnOnce( io::Result<()> ) + Send + 'static ) -> Operation
{
	Operation { handle: backend::copy( from.into(), to.into(), false, Box::new( progress ), Box::new( done ) ) }
}

pub fn copy_all( from: impl Into<PathBuf>, to: impl Into<PathBuf>, progress: impl Fn( u64, u64 ) + Send + 'static, done: impl FnOnce( io::Result<()> ) + Send + 'static ) -> Operation
{
	Operation { handle: backend::copy( from.into(), to.into(), true, Box::new( progress ), Box::new( done ) ) }
}

/// Have the browser ask the user for a folder of their computer and mount it, soon after the user's press; natively it fails with `Unsupported`.
pub fn mount( done: impl FnOnce( io::Result<Mount> ) + Send + 'static )
{
	backend::mount( Box::new( done ) );
}

pub fn unmount( path: impl Into<PathBuf>, done: impl FnOnce( io::Result<()> ) + Send + 'static )
{
	backend::unmount( path.into(), Box::new( done ) );
}