mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Merge pull request #1433 from NativeScript/file-binary-read-write
binary sync read/write added
This commit is contained in:
@@ -10,6 +10,7 @@ import fs = require("file-system");
|
||||
|
||||
import TKUnit = require("./TKUnit");
|
||||
import appModule = require("application");
|
||||
import platform = require("platform");
|
||||
|
||||
// <snippet module="file-system" title="file-system">
|
||||
// ## Path
|
||||
@@ -224,6 +225,34 @@ export var testFileRead = function () {
|
||||
// </snippet>
|
||||
};
|
||||
|
||||
export var testFileReadWriteBinary = function () {
|
||||
// <snippet module="file-system" title="file-system">
|
||||
// ### Reading/writing binary data from/to a File
|
||||
// ``` JavaScript
|
||||
var fileName = "logo.png";
|
||||
var error;
|
||||
|
||||
var sourceFile = fs.knownFolders.currentApp().getFile(fileName);
|
||||
var destinationFile = fs.knownFolders.documents().getFile(fileName);
|
||||
|
||||
var source = sourceFile.readSync(e=> { error = e; });
|
||||
|
||||
destinationFile.writeSync(source, e=> { error = e; });
|
||||
|
||||
// <hide>
|
||||
var destination = destinationFile.readSync(e=> { error = e; });
|
||||
TKUnit.assertNull(error);
|
||||
if (platform.device.os === platform.platformNames.ios) {
|
||||
TKUnit.assertTrue(source.isEqualToData(destination));
|
||||
} else {
|
||||
TKUnit.assertEqual(source, destination);
|
||||
}
|
||||
destinationFile.removeSync();
|
||||
// </hide>
|
||||
// ```
|
||||
// </snippet>
|
||||
};
|
||||
|
||||
export var testGetKnownFolders = function () {
|
||||
// <snippet module="file-system" title="file-system">
|
||||
// ### Getting the Known Folders
|
||||
|
||||
Reference in New Issue
Block a user