Added functions: exists(), writeFile()

This commit is contained in:
Volodymyr Kozieiev 2018-02-28 16:13:59 +02:00 committed by GitHub
parent d93c7be66f
commit 8a86ec9923
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 0 deletions

View File

@ -57,7 +57,10 @@ void RNFSManager::readDir(QString dirPath, const ModuleInterface::ListArgumentBl
}
void RNFSManager::exists(QString filepath, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject) {
Q_D(RNFSManager);
QFile file(filepath);
resolve(d->bridge, QVariantList{{QVariant(file.exists())}});
}
void RNFSManager::stat(QString filepath, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject) {
@ -65,7 +68,18 @@ void RNFSManager::stat(QString filepath, const ModuleInterface::ListArgumentBloc
}
void RNFSManager::writeFile(QString filepath, QString base64Content, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject) {
Q_D(RNFSManager);
QFile file(filepath);
if (!file.open(QIODevice::WriteOnly)) {
reject(d->bridge, QVariantList());
return;
}
QString content(QByteArray::fromBase64(base64Content.toUtf8()));
file.write(content.toStdString().c_str(), content.length());
resolve(d->bridge, QVariantList());
file.close();
}
void RNFSManager::appendFile(QString filepath, QString base64Content, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject) {