Quark
#
Modules #
quark/actionquark/appquark/bubblesquark/bufferquark/checkboxquark/cssquark/ctrquark/dialogquark/eventquark/fontquark/fsquark/hashquark/httpquark/indexquark/jsonbquark/keyboardquark/mediaquark/navquark/netquark/osquark/pathquark/pkgquark/screenquark/stepperquark/storagequark/testquark/typesquark/utilquark/viewquark/windowquark/wsquark/_bufferquark/_commonquark/_eventquark/_extquark/_md5quark/_sha1quark/_sha256quark/_utilquark/_watching
Quark v1.3.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_ACCMODEFOPEN_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
@constdefaultMode:
StreamResponseCallback #
@callbackStreamResponseCallback(stream)@paramstream: {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?
@returnboolean
filestat.isFile() #
Is it a normal file?
@returnboolean
filestat.isDir() #
Is it a directory?
@returnboolean
filestat.isLink() #
Is it a symbolic link?
@returnboolean
filestat.isSock() #
Is it a socket?
@returnboolean
filestat.mode() #
File permission mask
@returnnumber
filestat.type() #
File type
@returnFileType
filestat.group() #
System Group ID
@returnnumber
filestat.owner() #
System User ID
@returnnumber
filestat.size() #
File size
@returnnumber
filestat.nlink() #
Number of hard links to the file
@returnnumber
filestat.ino() #
The file system specific "Inode" number of the file
@returnnumber
filestat.blksize() #
The file system block size used for I/O operations
@returnnumber
filestat.blocks() #
The number of blocks allocated for this file
@returnnumber
filestat.flags() #
flags
@returnnumber
filestat.gen() #
gen
@returnnumber
filestat.dev() #
The device ID that contains the file
@returnnumber
filestat.rdev() #
If the file represents a device, the numeric device identifier
@returnnumber
filestat.atime() #
Timestamp indicating the last time this file was accessed
@returnnumber
filestat.mtime() #
A timestamp indicating when this file was last modified
@returnnumber
filestat.ctime() #
Timestamp indicating the last time the file's status changed
@returnnumber
filestat.birthtime() #
A timestamp indicating when this file was created
@returnnumber
Interface: Stream #
Stream #
stream.pause() #
Pause stream reading
@returnvoid
stream.resume() #
Resume stream reading
@returnvoid
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 #
@extendsPromise@template<T>
asynctask.id #
Asynchronous I/O task id
@getid:
asynctask.complete #
Whether the asynchronous task is completed
@getcomplete:
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.
@parammode?:UintdefaultMode@parampath:string@returnvoid
mkdirsSync(path,mode?) #
Synchronously recursively create directories,
and no exception is thrown if the directory exists
@parammode?:UintdefaultMode@parampath:string@returnvoid
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)
@parammode?:UintdefaultMode
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)
@paramowner:UintSystem User ID@paramgroup:UintSystem Group ID@parampath:string@returnvoid
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
@paramsize?:UintWrite all data when no parameters are passed@parampath:string@paramdata:Uint8Array@returnUint
writeFileSync(path,data,encoding?) #
Synchronously write a string to a file
@paramencoding?:EncodingIf not passed in, the default encoding isutf-8@parampath:string@paramdata:string@returnUint
readFileSync(path) #
Reading files synchronously
@parampath:string@returnUint8Array
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
@paramflags?:FileOpenFlagOpen file flags mask Default as FileOpenFlag.FOPEN_R@parampath:string@returnUint
closeSync(fd) #
Close the file handle synchronously
readSync(fd,out,size?,offsetFd?) #
Synchronously read the file contents from the file handle
@paramfd:UintOpen file handles@paramout:Uint8ArrayRead the file and save it here@paramsize?:IntIf not passed or passed in-1, the length of theoutparameter is used@paramoffsetFd?:IntIf not passed or -1 is passed,
the internal offset value of the file handle is used (it will advance after each read)@returnUintReturns the size of the data actually read
writeSync(fd,data,size?,offsetFd?) #
Synchronously write data to a file handle
@paramfd:UintOpen file handles@paramdata:Uint8ArrayData to be written@paramsize?:IntIf not passed or-1is passed, all data will be written@paramoffsetFd?:IntIf not passed or-1is passed, the internal offset value of
the file handle is used (it will advance after each write)@returnUintThe actual size of the data written
writeSync(fd,data,offsetFd?) #
Write data to the file handle synchronously and encode the data using utf-8
@paramfd:UintOpen file handles@paramdata:stringThe string to be written@paramoffsetFd?:IntIf not passed or-1is passed, the internal offset value of
the file handle is used (it will advance after each write)@returnUintThe actual size of the data written
writeSync(fd,data,encoding,offsetFd?) #
Synchronously write data to a file handle
@paramfd:UintOpen file handles@paramdata:stringData to be written@paramencoding:EncodingEncoding Type@paramoffsetFd?:IntIf not passed or-1is passed, the internal offset value of
the file handle is used (it will advance after each write)@returnUintThe 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])]
@parampath:string@parammode?:UintdefaultMode@returnPromise
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)
@parampath:string
rmdir(path) #
Please ref: sync method rmdirSync(path)
@parampath: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
@parampath:string@parammode?:UintdefaultMode@returnAsyncTask
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
@parampath:stringRead the target path@paramcb:StreamResponseCallbackAsynchronous stream callback function@returnAsyncTask<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?)
@parampath:string@paramdata:Uint8Array@paramsize?:Uint@returnPromise<Uint>
writeFile(path,data,encoding?) #
Please ref: sync method writeFileSync(path,data,encoding?)
readFile(path) #
Please ref: sync method readFileSync(path)
@parampath:string@returnPromise<Uint8Array>
readFile(path,encoding) #
Please ref: sync method readFileSync(path,encoding)
open(path,flags?) #
Please ref: sync method openSync(path,flags?)
@parampath:string@paramflags?:FileOpenFlag@returnPromise<Uint>
close(fd) #
Please ref: sync method closeSync(fd)
read(fd,out,size?,offsetFd?) #
Please ref: sync method readSync(fd,out,size?,offsetFd?)
@paramfd:Uint@paramout:Uint8Array@paramsize?:Int@paramoffsetFd?:Int@returnPromise<Uint>
write(fd,data,size?,offsetFd?) #
Please ref: sync method writeSync(fd,data,size?,offsetFd?)
@paramfd:Uint@paramdata:Uint8Array@paramsize?:Int@paramoffsetFd?:Int@returnPromise<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?)
@paramfd:Uint@paramdata:string@paramencoding:Encoding@paramoffsetFd?:Int@returnPromise<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/dataorvar/datacan be used as local paths without error.zip://This is a way to represent the path in thezippackage,zip:///var/data/test.zip@/a.txt
This path represents thea.txtfile 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(()=>{
// Success
}).catch(err=>{
// Fail
})
@parampath:string@returnAsyncTask<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', 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);
});
@parampath:string@paramcb:StreamResponseCallback@returnAsyncTask<void>
reader.readFileSync(path) #
Please ref: method Reader.readFile(path)
@parampath:string@returnUint8Array
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
@returnvoid
reader #
@constreader:Reader