DataAdapter
Work directly with files and folders inside a vault. If possible prefer using the Vault API over this.
Extends
Extended by
Properties
basePath
basePath:
string
Base OS path for the vault (e.g. /home/user/vault, or C:\Users\user\documents\vault)
files
files:
DataAdapterFilesRecord
Mapping of file/folder path to vault entry, includes non-MD files
Methods
append()
append(
normalizedPath
,data
,options
?):Promise
<void
>
Add text to the end of a plaintext file.
Parameters
• normalizedPath: string
path to file, use normalizePath to normalize beforehand.
• data: string
the text to append.
• options?: DataWriteOptions
(Optional)
Returns
Promise
<void
>
copy()
copy(
normalizedPath
,normalizedNewPath
):Promise
<void
>
Create a copy of a file.
This will fail if there is already a file at normalizedNewPath
.
Parameters
• normalizedPath: string
path to file, use normalizePath to normalize beforehand.
• normalizedNewPath: string
path to file, use normalizePath to normalize beforehand.
Returns
Promise
<void
>
exists()
exists(
normalizedPath
,sensitive
?):Promise
<boolean
>
Check if something exists at the given path.
Parameters
• normalizedPath: string
path to file/folder, use normalizePath to normalize beforehand.
• sensitive?: boolean
Some file systems/operating systems are case-insensitive, set to true to force a case-sensitivity check.
Returns
Promise
<boolean
>
getFullPath()
getFullPath(
normalizedPath
):string
Get full path of file (OS path)
Parameters
• normalizedPath: string
Path to file
Returns
string
String full path to file
getFullRealPath()
getFullRealPath(
normalizedPath
):string
Get full path of file (OS path)
Parameters
• normalizedPath: string
Path to file
Returns
string
String full path to file
getName()
getName():
string
Returns
string
getResourcePath()
getResourcePath(
normalizedPath
):string
Returns an URI for the browser engine to use, for example to embed an image.
Parameters
• normalizedPath: string
path to file/folder, use normalizePath to normalize beforehand.
Returns
string
list()
list(
normalizedPath
):Promise
<ListedFiles
>
Retrieve a list of all files and folders inside the given folder, non-recursive.
Parameters
• normalizedPath: string
path to folder, use normalizePath to normalize beforehand.
Returns
mkdir()
mkdir(
normalizedPath
):Promise
<void
>
Create a directory.
Parameters
• normalizedPath: string
path to use for new folder, use normalizePath to normalize beforehand.
Returns
Promise
<void
>
process()
process(
normalizedPath
,fn
,options
?):Promise
<string
>
Atomically read, modify, and save the contents of a plaintext file.
Parameters
• normalizedPath: string
path to file/folder, use normalizePath to normalize beforehand.
• fn
a callback function which returns the new content of the file synchronously.
• options?: DataWriteOptions
write options.
Returns
Promise
<string
>
string - the text value of the file that was written.
queue()
queue(
next
):Promise
<void
>
Parameters
• next
Returns
Promise
<void
>
Inherited from
read()
read(
normalizedPath
):Promise
<string
>
Parameters
• normalizedPath: string
path to file, use normalizePath to normalize beforehand.
Returns
Promise
<string
>
readBinary()
readBinary(
normalizedPath
):Promise
<ArrayBuffer
>
Parameters
• normalizedPath: string
path to file, use normalizePath to normalize beforehand.
Returns
remove()
remove(
normalizedPath
):Promise
<void
>
Delete a file.
Parameters
• normalizedPath: string
path to file, use normalizePath to normalize beforehand.
Returns
Promise
<void
>
rename()
rename(
normalizedPath
,normalizedNewPath
):Promise
<void
>
Rename a file or folder.
Parameters
• normalizedPath: string
current path to file/folder, use normalizePath to normalize beforehand.
• normalizedNewPath: string
new path to file/folder, use normalizePath to normalize beforehand.
Returns
Promise
<void
>
rmdir()
rmdir(
normalizedPath
,recursive
):Promise
<void
>
Remove a directory.
Parameters
• normalizedPath: string
path to folder, use normalizePath to normalize beforehand.
• recursive: boolean
If true
, delete folders under this folder recursively, if false
the folder needs to be empty.
Returns
Promise
<void
>
stat()
Retrieve metadata about the given file/folder.
Parameters
• normalizedPath: string
path to file/folder, use normalizePath to normalize beforehand.
Returns
trashLocal()
trashLocal(
normalizedPath
):Promise
<void
>
Move to local trash.
Files will be moved into the .trash
folder at the root of the vault.
Parameters
• normalizedPath: string
path to file/folder, use normalizePath to normalize beforehand.
Returns
Promise
<void
>
trashSystem()
trashSystem(
normalizedPath
):Promise
<boolean
>
Try moving to system trash.
Parameters
• normalizedPath: string
path to file/folder, use normalizePath to normalize beforehand.
Returns
Promise
<boolean
>
Returns true if succeeded. This can fail due to system trash being disabled.
write()
write(
normalizedPath
,data
,options
?):Promise
<void
>
Write to a plaintext file. If the file exists its content will be overwritten, otherwise the file will be created.
Parameters
• normalizedPath: string
path to file, use normalizePath to normalize beforehand.
• data: string
new file content
• options?: DataWriteOptions
(Optional)
Returns
Promise
<void
>
writeBinary()
writeBinary(
normalizedPath
,data
,options
?):Promise
<void
>
Write to a binary file. If the file exists its content will be overwritten, otherwise the file will be created.
Parameters
• normalizedPath: string
path to file, use normalizePath to normalize beforehand.
• data: ArrayBuffer
the new file content
• options?: DataWriteOptions
(Optional)
Returns
Promise
<void
>