feat(file-system): allow copy when opening a File (#10274)

* feat: add copy file to file-system

* feat(file-system): allow temp copy of files opened with File.fromPath

* chore: remove log

* chore: remove log

* fix: only copy if true

---------

Co-authored-by: Nathan Walker <walkerrunpdx@gmail.com>
This commit is contained in:
Osei Fortune
2023-04-25 00:30:28 -04:00
committed by GitHub
parent 4551da075b
commit 18bba2bc11
7 changed files with 104 additions and 34 deletions

View File

@@ -698,3 +698,24 @@ export function test_FolderClear_RemovesEmptySubfolders(done) {
})
.catch(done);
}
export function test_FileCopy(done) {
const now = Date.now();
const tempFile = fs.File.fromPath(fs.path.join(fs.knownFolders.temp().path, `${now}.txt`));
const content = 'Hello World: ' + now;
tempFile.writeTextSync(content);
const tempCopy = fs.File.fromPath(fs.path.join(fs.knownFolders.temp().path, `${now}-copy.txt`));
tempFile
.copy(tempCopy.path)
.then(() => {
TKUnit.assert(tempCopy.size === tempFile.size);
return tempCopy.readText();
})
.then((value) => {
TKUnit.assert(value === content);
return Promise.allSettled([tempFile.remove(), tempCopy.remove()]);
})
.then(() => done())
.catch(done);
}

View File

@@ -110,7 +110,12 @@ export function pickFile() {
//const file = File.fromPath(args.intent.getData().toString());
//console.log(file);
//readFile(file);
copyFile(file);
//copyFile(file);
console.time('fromPath: copy');
const f = File.fromPath(file, true);
console.timeEnd('fromPath: copy');
console.log('old path: ', file);
console.log('new path: ', f.path, f.extension, f.size);
}
});
const Intent = android.content.Intent;