Quark
#
Modules #
quark/action
quark/app
quark/bubbles
quark/buffer
quark/checkbox
quark/css
quark/ctr
quark/dialog
quark/event
quark/font
quark/fs
quark/http
quark/index
quark/keyboard
quark/media
quark/nav
quark/os
quark/path
quark/pkg
quark/screen
quark/stepper
quark/storage
quark/test
quark/types
quark/util
quark/view
quark/window
quark/_common
quark/_event
quark/_ext
quark/_util
Quark v1.2.0 Documentation
Table of Contents
-
quark/fs
- Enum: FileOpenFlag
- Enum: FileType
- defaultMode
- StreamResponseCallback
- Interface: Dirent
-
Class: FileStat
- FileStat
- filestat.isValid()
- filestat.isFile()
- filestat.isDir()
- filestat.isLink()
- filestat.isSock()
- filestat.mode()
- filestat.type()
- filestat.group()
- filestat.owner()
- filestat.size()
- filestat.nlink()
- filestat.ino()
- filestat.blksize()
- filestat.blocks()
- filestat.flags()
- filestat.gen()
- filestat.dev()
- filestat.rdev()
- filestat.atime()
- filestat.mtime()
- filestat.ctime()
- filestat.birthtime()
- Interface: Stream
- Interface: StreamResponse
- Class: AsyncTask
- chmodSync(path,mode?)
- chownSync(path,owner,group)
- mkdirSync(path,mode?)
- mkdirsSync(path,mode?)
- renameSync(name,newName)
- linkSync(src,target)
- unlinkSync(path)
- rmdirSync(path)
- readdirSync(path)
- statSync(path)
- existsSync(path)
- isFileSync(path)
- isDirectorySync(path)
- readableSync(path)
- writableSync(path)
- executableSync(path)
- chmodRecursionSync(path,mode?)
- chownRecursionSync(path,owner,group)
- removeRecursionSync(path)
- copyRecursionSync(path,target)
- copySync(path,target)
- writeFileSync(path,data,size?)
- writeFileSync(path,data,encoding?)
- readFileSync(path)
- readFileSync(path,encoding)
- openSync(path,flags?)
- closeSync(fd)
- readSync(fd,out,size?,offsetFd?)
- writeSync(fd,data,size?,offsetFd?)
- writeSync(fd,data,offsetFd?)
- writeSync(fd,data,encoding,offsetFd?)
- chmod(path,mode?)
- chown(path,owner,group)
- chmod(path,mode?)
- mkdirs(path,mode?)
- rename(name,newName)
- link(src,target)
- unlink(path)
- rmdir(path)
- readdir(path)
- stat(path)
- exists(path)
- isFile(path)
- isDirectory(path)
- readable(path)
- writable(path)
- executable(path)
- chmodRecursion(path,mode?)
- chownRecursion(path,owner,group)
- removeRecursion(path)
- copyRecursion(path,target)
- copy(path,target)
- readStream(path,cb)
- abort(id)
- writeFile(path,data,size?)
- writeFile(path,data,encoding?)
- readFile(path)
- readFile(path,encoding)
- open(path,flags?)
- close(fd)
- read(fd,out,size?,offsetFd?)
- write(fd,data,size?,offsetFd?)
- write(fd,data,offsetFd?)
- write(fd,data,encoding,offsetFd?)
- Interface: Reader
- reader
quark/fs #
Enum: FileOpenFlag #
FileOpenFlag #
Opening file Flags
FOPEN_ACCMODE
FOPEN_RDONLY
Open a read-only file. The file must exist.FOPEN_WRONLY
Open a write-only file. The file must exist.FOPEN_RDWR
Open a file for reading and writing. The file must exist.FOPEN_CREAT
Create the file if it does not existFOPEN_EXCL
Create a file as executableFOPEN_NOCTTY
No Controlling TTYFOPEN_TRUNC
Clear the file contents if the file existsFOPEN_APPEND
Move the file read cursor to the end if the file existsFOPEN_NONBLOCK
Blocking mode, usually using the open functionFOPEN_R
r, open the file for reading only, the file must existFOPEN_W
w, Open a write-only file. If the file exists, the file length is cleared to zero, that is,
the file content will disappear. If the file does not exist, it will be created.FOPEN_A
a, Open a write-only file in append mode. If the file does not exist, it will be created.
If the file exists, the written data will be added to the end of the file, that is,
the original content of the file will be retained.FOPEN_RP
r+,
Open a file for reading and writing. The file must exist.FOPEN_WP
w+, Open the file for reading and writing. If the file exists,
the file length will be cleared to zero, that is, the file content will disappear.
If the file does not exist, it will be created.FOPEN_AP
a+, Open a readable and writable file in append mode. If the file does not exist,
it will be created. If the file exists, the written data will be added to the end of the file,
that is, the original content of the file will be retained.
Enum: FileType #
FileType #
File type
FTYPE_UNKNOWN
Unknown TypeFTYPE_FILE
Normal FileFTYPE_DIR
Directory)FTYPE_LINK
Symbolic link files(Soft Link)FTYPE_FIFO
Named pipes, a special type of file used for interprocess communication (IPC)FTYPE_SOCKET
SocketFTYPE_CHAR
Unbuffered character devices, such as keyboard and mouse (/dev/input/), terminal (/dev/tty)FTYPE_BLOCK
Provides buffered, block-oriented (fixed-size data blocks) I/O access,
such as hard disk drives (/dev/sda, /dev/sda1, /dev/nvme0n1p1)
defaultMode #
Create and set the default mode
value of the file,
which is related to the file's permissions. This is an int
integer type value
@const
defaultMode
:
StreamResponseCallback #
@callback
StreamResponseCallback(stream)
@param
stream
: {StreamResponse}
Interface: Dirent #
Dirent #
The result returned by calling readdir/readdirSync
dirent.name #
File name
name
:string
dirent.pathname #
The full path to the file
pathname
:string
dirent.type #
File Type
type
:FileType
Class: FileStat #
FileStat #
filestat.isValid() #
Is the file valid?
@return
boolean
filestat.isFile() #
Is it a normal file?
@return
boolean
filestat.isDir() #
Is it a directory?
@return
boolean
filestat.isLink() #
Is it a symbolic link?
@return
boolean
filestat.isSock() #
Is it a socket?
@return
boolean
filestat.mode() #
File permission mask
@return
number
filestat.type() #
File type
@return
FileType
filestat.group() #
System Group ID
@return
number
filestat.owner() #
System User ID
@return
number
filestat.size() #
File size
@return
number
filestat.nlink() #
Number of hard links to the file
@return
number
filestat.ino() #
The file system specific "Inode" number of the file
@return
number
filestat.blksize() #
The file system block size used for I/O operations
@return
number
filestat.blocks() #
The number of blocks allocated for this file
@return
number
filestat.flags() #
flags
@return
number
filestat.gen() #
gen
@return
number
filestat.dev() #
The device ID that contains the file
@return
number
filestat.rdev() #
If the file represents a device, the numeric device identifier
@return
number
filestat.atime() #
Timestamp indicating the last time this file was accessed
@return
number
filestat.mtime() #
A timestamp indicating when this file was last modified
@return
number
filestat.ctime() #
Timestamp indicating the last time the file's status changed
@return
number
filestat.birthtime() #
A timestamp indicating when this file was created
@return
number
Interface: Stream #
Stream #
stream.pause() #
Pause stream reading
@return
void
stream.resume() #
Resume stream reading
@return
void
Interface: StreamResponse #
StreamResponse #
streamresponse.size #
Data size
size
:number
streamresponse.total #
Total data size
total
:number
streamresponse.data #
It is Data
data
:Uint8Array
streamresponse.ended #
Is it over
ended
:boolean
Class: AsyncTask #
AsyncTask #
@extends
Promise
@template
<T
>
asynctask.id #
Asynchronous I/O task id
@get
id
:
asynctask.complete #
Whether the asynchronous task is completed
@get
complete
:
asynctask.abort(reason?) #
Abort I/O task
chmodSync(path,mode?) #
Synchronously change file permissions
chmodSync('my_file.txt', 0o775)
chownSync(path,owner,group) #
Synchronize the owner
and group
of the configuration file
mkdirSync(path,mode?) #
Create a directory synchronously. If the path already exists, an exception will be thrown.
@param
mode?
:Uint
defaultMode
@param
path
:string
@return
void
mkdirsSync(path,mode?) #
Synchronously recursively create directories,
and no exception is thrown if the directory exists
@param
mode?
:Uint
defaultMode
@param
path
:string
@return
void
renameSync(name,newName) #
Synchronously rename files and directories
linkSync(src,target) #
Synchronously create file hard links
unlinkSync(path) #
Synchronously delete the file hard link.
If the file has only one link, the file will be physically deleted.
rmdirSync(path) #
Synchronously delete the file directory, the file directory must be empty
readdirSync(path) #
Synchronously read the file directory file list
statSync(path) #
Synchronously read file status information
existsSync(path) #
Synchronously check if a file exists
isFileSync(path) #
Synchronously checks if the path is a file, and returns false
if the path does not exist
isDirectorySync(path) #
Synchronously checks if the path is a directory, and returns false
if the path does not exist
readableSync(path) #
Synchronously checks if the path is readable, returning false
if the path does not exist
writableSync(path) #
Synchronously checks if the path is writable, returning false
if the path does not exist
executableSync(path) #
Synchronously checks if it is executable, returns false
if the path does not exist
chmodRecursionSync(path,mode?) #
Synchronously recursively set the file permission attribute mode
(TODO: will block the calling thread, please use with caution)
@param
mode?
:Uint
defaultMode
For example:
fs.chmodRecursionSync(mypath, 0755);
chownRecursionSync(path,owner,group) #
Synchronously recursively set file owner
and group
attributes
(TODO: will block the calling thread, please use with caution)
@param
owner
:Uint
System User ID@param
group
:Uint
System Group ID@param
path
:string
@return
void
removeRecursionSync(path) #
Synchronous recursive deletion of directories or files,
use this method with caution, it may cause the thread to be blocked for a long time
copyRecursionSync(path,target) #
Synchronous recursive copy of files,
use this method with caution, it may cause the thread to be blocked for a long time
copySync(path,target) #
Copy files synchronously (TODO: will block the calling thread, please use with caution)
Same as: copy files and directoriescopyRecursionSync(path,target)
writeFileSync(path,data,size?) #
Synchronously write data to a file
@param
size?
:Uint
Write all data when no parameters are passed@param
path
:string
@param
data
:Uint8Array
@return
Uint
writeFileSync(path,data,encoding?) #
Synchronously write a string to a file
@param
encoding?
:Encoding
If not passed in, the default encoding isutf-8
@param
path
:string
@param
data
:string
@return
Uint
readFileSync(path) #
Reading files synchronously
@param
path
:string
@return
Uint8Array
readFileSync(path,encoding) #
Synchronously read a file as a string
openSync(path,flags?) #
Opens a file by path synchronously and returns an open file handle
@param
flags?
:FileOpenFlag
Open file flags mask Default as FileOpenFlag.FOPEN_R@param
path
:string
@return
Uint
closeSync(fd) #
Close the file handle synchronously
readSync(fd,out,size?,offsetFd?) #
Synchronously read the file contents from the file handle
@param
fd
:Uint
Open file handles@param
out
:Uint8Array
Read the file and save it here@param
size?
:Int
If not passed or passed in-1
, the length of theout
parameter is used@param
offsetFd?
:Int
If not passed or -1 is passed,
the internal offset value of the file handle is used (it will advance after each read)@return
Uint
Returns the size of the data actually read
writeSync(fd,data,size?,offsetFd?) #
Synchronously write data to a file handle
@param
fd
:Uint
Open file handles@param
data
:Uint8Array
Data to be written@param
size?
:Int
If not passed or-1
is passed, all data will be written@param
offsetFd?
:Int
If not passed or-1
is passed, the internal offset value of
the file handle is used (it will advance after each write)@return
Uint
The actual size of the data written
writeSync(fd,data,offsetFd?) #
Write data to the file handle synchronously and encode the data using utf-8
@param
fd
:Uint
Open file handles@param
data
:string
The string to be written@param
offsetFd?
:Int
If not passed or-1
is passed, the internal offset value of
the file handle is used (it will advance after each write)@return
Uint
The actual size of the data written
writeSync(fd,data,encoding,offsetFd?) #
Synchronously write data to a file handle
@param
fd
:Uint
Open file handles@param
data
:string
Data to be written@param
encoding
:Encoding
Encoding Type@param
offsetFd?
:Int
If not passed or-1
is passed, the internal offset value of
the file handle is used (it will advance after each write)@return
Uint
The actual size of the data written
chmod(path,mode?) #
Please ref: sync method chmodSync(path,mode?)
chown(path,owner,group) #
Please ref: sync method chownSync(path,owner,group)
chmod(path,mode?) #
Please ref: sync method mkdirSync(path,mode?)
mkdirs(path,mode?) #
Recursively create directories. This method will create
a directory tree in sequence, and will not throw an exception if the directory exists.
Ref: sync method [mkdirsSync(path[,mode])
]
@param
path
:string
@param
mode?
:Uint
defaultMode
@return
Promise
For example:
fs.mkdirs(mypath).then(()=>{
// Success
}).catch(err=>{
// Fail
});
rename(name,newName) #
Please ref: sync method renameSync(name,newName)
link(src,target) #
Please ref: sync method linkSync(src,target)
unlink(path) #
Please ref: sync method unlinkSync(path)
@param
path
:string
rmdir(path) #
Please ref: sync method rmdirSync(path)
@param
path
:string
readdir(path) #
Read directory listing information. Throws an exception if failed.
Returns an Array
of Dirent
if successful.
For example:
// Prints:
// {
// name: "cp.txt",
// pathname: "file:///var/mobile/Containers/Data/Application/64DAC3FC-A4FD-4274-A2E7-B834EE4930B4/Documents/test/cp.txt",
// type: 1
// }
fs.readdir(mydir).then(dirents=>{
for (var dirent of dirents) {
// TODO...
console.log(dirent);
}
}).catch(err=>{
// Fail
});
stat(path) #
Please ref: sync method statSync(path)
exists(path) #
Please ref: sync method existsSync(path)
isFile(path) #
Please ref: sync method isFileSync(path)
isDirectory(path) #
Please ref: sync method isDirectorySync(path)
readable(path) #
Please ref: sync method readableSync(path)
writable(path) #
Please ref: sync method writableSync(path)
executable(path) #
Please ref: sync method executableSync(path)
chmodRecursion(path,mode?) #
Asynchronously recursively set the mode
attribute of a file or directory
@param
path
:string
@param
mode?
:Uint
defaultMode
@return
AsyncTask
Example:
// `mypath`For the file path, it can be a file or a directory
fs.chmodR(mypath, 0755).then(function() {
console.log('Success');
}).catch(err=>{
console.log('Fail');
});
var id = fs.chmodR(mydir, 0775);
fs.abort(id);
chownRecursion(path,owner,group) #
Asynchronously recursively set the owner
and group
attributes of files or directories
For example:
var task = chownRecursion(mypath, 501, 501);
fs.abort(task.id); // force abort task
removeRecursion(path) #
Recursively delete files and directories
For example:
var task = fs.removeRecursion(mypath);
task.then(()=>{
// Success
}).catch(err=>{
// Fail
});
// The deletion task can be aborted by id
fs.abort(task.id);
copyRecursion(path,target) #
Recursively copy files
The difference between copyRecursion()
and copy()
is that copy()
can only copy a single file
For example:
fs.copy(source, target).then(()=>{
// Success
}).catch(err=>{
// Fail
});
copy(path,target) #
Copy a single file
Ref: copyRecursion(path,target)
readStream(path,cb) #
Read file contents using asynchronous streaming
@param
path
:string
Read the target path@param
cb
:StreamResponseCallback
Asynchronous stream callback function@return
AsyncTask
<void
>
abort(id) #
Force abort a running asynchronous task by id
If a meaningless id
is passed in or the task to which
the id
belongs has been completed, no processing will be done
For example:
var a = fs.chmod(mypath, 0o755);
var b = fs.chown(mypath, 501, 501);
var c = fs.copy(mypath, newpath);
// force abort task
fs.abort(a.id);
fs.abort(b.id);
fs.abort(c.id);
writeFile(path,data,size?) #
Please ref: sync method writeFileSync(path,data,size?)
@param
path
:string
@param
data
:Uint8Array
@param
size?
:Uint
@return
Promise
<Uint
>
writeFile(path,data,encoding?) #
Please ref: sync method writeFileSync(path,data,encoding?)
readFile(path) #
Please ref: sync method readFileSync(path)
@param
path
:string
@return
Promise
<Uint8Array
>
readFile(path,encoding) #
Please ref: sync method readFileSync(path,encoding)
open(path,flags?) #
Please ref: sync method openSync(path,flags?)
@param
path
:string
@param
flags?
:FileOpenFlag
@return
Promise
<Uint
>
close(fd) #
Please ref: sync method closeSync(fd)
read(fd,out,size?,offsetFd?) #
Please ref: sync method readSync(fd,out,size?,offsetFd?)
@param
fd
:Uint
@param
out
:Uint8Array
@param
size?
:Int
@param
offsetFd?
:Int
@return
Promise
<Uint
>
write(fd,data,size?,offsetFd?) #
Please ref: sync method writeSync(fd,data,size?,offsetFd?)
@param
fd
:Uint
@param
data
:Uint8Array
@param
size?
:Int
@param
offsetFd?
:Int
@return
Promise
<Uint
>
write(fd,data,offsetFd?) #
Please ref: sync method writeSync(fd,data,offsetFd?)
write(fd,data,encoding,offsetFd?) #
Please ref: sync method writeSync(fd,data,encoding,offsetFd?)
@param
fd
:Uint
@param
data
:string
@param
encoding
:Encoding
@param
offsetFd?
:Int
@return
Promise
<Uint
>
Interface: Reader #
Reader #
The methods provided here can perform basic read operations on URI paths of different protocols
Currently supported path types:
http://
orhttps://
- can be read synchronously or asynchronously, but cannot read directories or test existence,readdirSync()
returns an empty array andisFileSync()
always returnsfalse
.file://
local file path./var/data
orvar/data
can be used as local paths without error.zip://
This is a way to represent the path in thezip
package,zip:///var/data/test.zip@/a.txt
This path represents thea.txt
file inzip:///var/data/test.zip
. Note that this path must exist in the local file system
reader.readFile(path) #
Reading file data
For example:
reader.readFile('[`http://xxx.com/test.txt').then(()=>{`](http://xxx.com/test.txt').then(()=>{)
// Success
}).catch(err=>{
// Fail
})
@param
path
:string
@return
AsyncTask
<Uint8Array
>
reader.readFile(path,encoding) #
Read file data and decode it into a string
reader.readStream(path,cb) #
Read file data by asynchronous streaming
For example:
// async read file stream
reader.readStream('[`http://www.baidu.com',`](http://www.baidu.com',) function(d){}));
reader.readStream('file:///var/data/test.txt', function(d){}));
reader.readStream('zip:///var/data/test.zip@aa.txt', function(d){
// Success
console.log(d.data.length, d.ended);
});
@param
path
:string
@param
cb
:StreamResponseCallback
@return
AsyncTask
<void
>
reader.readFileSync(path) #
Please ref: method Reader.readFile(path)
@param
path
:string
@return
Uint8Array
reader.readFileSync(path,encoding) #
Please ref: method Reader.readFile(path,encoding)
reader.existsSync(path) #
同步测试文件或目录是否存在,如果文件存在会返回false
这个方法不能处理http://
与https://
类型的路径,如果传入这种路径立即返回false
Synchronously test whether a file or directory exists. If the file exists, it will return false
This method cannot handle paths of the http://
and https://
type. If such a path is passed, it will immediately return false
reader.isFileSync(path) #
同步检查路径是否为文件,如果路径不存在返回 false
这个方法不能处理http://
与https://
类型的路径,如果传入这种路径立即返回false
Synchronously check if the path is a file, and return false
if the path does not exist
This method cannot handle http://
and https://
type paths, and immediately returns false
if such a path is passed
reader.isDirectorySync(path) #
同步检查路径是否为目录,如果路径不存在返回 false
这个方法不能处理http://
与https://
类型的路径,如果传入这种路径立即返回false
Synchronously check if the path is a directory, and return false
if the path does not exist
This method cannot handle http://
and https://
type paths, and immediately returns false
if such a path is passed in
reader.readdirSync(path) #
同步读取目录文件列表,
这个方法不能处理http://
与https://
类型的路径,如果传入这种路径立即返回一个空数组Array
,
这个方法也不会抛出异常,如果不能读取路径,只会返回空数组Array
Synchronously read the directory file list,
This method cannot handle http://
and https://
type paths. If such a path is passed, an empty array Array
will be immediately returned.
This method will not throw an exception. If the path cannot be read, it will only return an empty array Array
reader.abort(id) #
Abort an asynchronous task by its id
reader.clear() #
To clear cache of reader
@return
void
reader #
@const
reader
:Reader