| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -186,7 +186,7 @@ export var testFileReadWriteBinary = function () { | |||
| 186 | 186 | var source = sourceFile.readSync(e=> { error = e; }); | |
| 187 | 187 | ||
| 188 | 188 | destinationFile.writeSync(source, e=> { error = e; }); | |
| 189 | - | ||
| 189 | + | ||
| 190 | 190 | // >> (hide) | |
| 191 | 191 | var destination = destinationFile.readSync(e=> { error = e; }); | |
| 192 | 192 | TKUnit.assertNull(error); | |
@@ -238,22 +238,22 @@ function _testIOSSpecificKnownFolder(knownFolderName: string){ | |||
| 238 | 238 | } | |
| 239 | 239 | } | |
| 240 | 240 | else { | |
| 241 | - TKUnit.assertThrows(testFunc, | ||
| 241 | + TKUnit.assertThrows(testFunc, | ||
| 242 | 242 | `Trying to retrieve the ${knownFolderName} known folder on a platform different from iOS should throw!`, | |
| 243 | 243 | `The "${knownFolderName}" known folder is available on iOS only!`); | |
| 244 | 244 | } | |
| 245 | 245 | } | |
| 246 | 246 | ||
| 247 | 247 | export var testIOSSpecificKnownFolders = function () { | |
| 248 | - _testIOSSpecificKnownFolder("library"); | ||
| 249 | - _testIOSSpecificKnownFolder("developer"); | ||
| 250 | - _testIOSSpecificKnownFolder("desktop"); | ||
| 251 | - _testIOSSpecificKnownFolder("downloads"); | ||
| 252 | - _testIOSSpecificKnownFolder("movies"); | ||
| 253 | - _testIOSSpecificKnownFolder("music"); | ||
| 254 | - _testIOSSpecificKnownFolder("pictures"); | ||
| 255 | - _testIOSSpecificKnownFolder("sharedPublic"); | ||
| 256 | - } | ||
| 248 | + _testIOSSpecificKnownFolder("library"); | ||
| 249 | + _testIOSSpecificKnownFolder("developer"); | ||
| 250 | + _testIOSSpecificKnownFolder("desktop"); | ||
| 251 | + _testIOSSpecificKnownFolder("downloads"); | ||
| 252 | + _testIOSSpecificKnownFolder("movies"); | ||
| 253 | + _testIOSSpecificKnownFolder("music"); | ||
| 254 | + _testIOSSpecificKnownFolder("pictures"); | ||
| 255 | + _testIOSSpecificKnownFolder("sharedPublic"); | ||
| 256 | + }; | ||
| 257 | 257 | ||
| 258 | 258 | export var testGetEntities = function () { | |
| 259 | 259 | // >> file-system-folders-content | |
@@ -559,12 +559,22 @@ export function test_FSEntity_Properties() { | |||
| 559 | 559 | TKUnit.assert(file.extension === ".txt", "FileEntity.extension not working."); | |
| 560 | 560 | TKUnit.assert(file.isLocked === false, "FileEntity.isLocked not working."); | |
| 561 | 561 | TKUnit.assert(file.lastModified instanceof Date, "FileEntity.lastModified not working."); | |
| 562 | + TKUnit.assert(file.size === 0, "FileEntity.size not working."); | ||
| 562 | 563 | TKUnit.assert(file.name === "Test_File.txt", "FileEntity.name not working."); | |
| 563 | 564 | TKUnit.assert(file.parent === documents, "FileEntity.parent not working."); | |
| 564 | 565 | ||
| 565 | 566 | file.remove(); | |
| 566 | 567 | } | |
| 567 | 568 | ||
| 569 | + export function test_FileSize(done) { | ||
| 570 | + var file = fs.knownFolders.documents().getFile("Test_File_Size.txt"); | ||
| 571 | + file.writeText("Hello World!").then(() => { | ||
| 572 | + TKUnit.assert(file.size === "Hello World!".length); | ||
| 573 | + return file.remove(); | ||
| 574 | + }).then(() => done()) | ||
| 575 | + .catch(done); | ||
| 576 | + } | ||
| 577 | + | ||
| 568 | 578 | export function test_UnlockAfterWrite(done) { | |
| 569 | 579 | var file = fs.knownFolders.documents().getFile("Test_File_Lock.txt"); | |
| 570 | 580 | file.writeText("Hello World!").then(() => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,6 +18,11 @@ export class FileSystemAccess { | |||
| 18 | 18 | return new Date(javaFile.lastModified()); | |
| 19 | 19 | } | |
| 20 | 20 | ||
| 21 | + public getFileSize(path: string): number { | ||
| 22 | + const javaFile = new java.io.File(path); | ||
| 23 | + return javaFile.length(); | ||
| 24 | + } | ||
| 25 | + | ||
| 21 | 26 | public getParent(path: string, onError?: (error: any) => any): { path: string; name: string } { | |
| 22 | 27 | try { | |
| 23 | 28 | var javaFile = new java.io.File(path); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,6 +12,12 @@ export class FileSystemAccess { | |||
| 12 | 12 | */ | |
| 13 | 13 | getLastModified(path: string): Date; | |
| 14 | 14 | ||
| 15 | + /** | ||
| 16 | + * Gets the size in bytes of a file with a given path. | ||
| 17 | + * @param path Path to the file. | ||
| 18 | + */ | ||
| 19 | + getFileSize(path: string): number; | ||
| 20 | + | ||
| 15 | 21 | /** | |
| 16 | 22 | * Gets the parent folder of a file with a given path. | |
| 17 | 23 | * @param path Path to the file. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,6 +16,16 @@ export class FileSystemAccess { | |||
| 16 | 16 | } | |
| 17 | 17 | } | |
| 18 | 18 | ||
| 19 | + public getFileSize(path: string): number { | ||
| 20 | + const fileManager = ios.getter(NSFileManager, NSFileManager.defaultManager); | ||
| 21 | + const attributes = fileManager.attributesOfItemAtPathError(path); | ||
| 22 | + if (attributes) { | ||
| 23 | + return attributes.objectForKey("NSFileSize"); | ||
| 24 | + } else { | ||
| 25 | + return 0; | ||
| 26 | + } | ||
| 27 | + } | ||
| 28 | + | ||
| 19 | 29 | public getParent(path: string, onError?: (error: any) => any): { path: string; name: string } { | |
| 20 | 30 | try { | |
| 21 | 31 | const fileManager = ios.getter(NSFileManager, NSFileManager.defaultManager); | |
@@ -386,4 +396,4 @@ export class FileSystemAccess { | |||
| 386 | 396 | public joinPaths(paths: string[]): string { | |
| 387 | 397 | return ios.joinPaths(...paths); | |
| 388 | 398 | } | |
| 389 | - } | ||
| 399 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,7 +23,7 @@ export class FileSystemEntity { | |||
| 23 | 23 | path: string; | |
| 24 | 24 | ||
| 25 | 25 | /** | |
| 26 | - * Gets the Folder object representing the parent of this entity. | ||
| 26 | + * Gets the Folder object representing the parent of this entity. | ||
| 27 | 27 | * Will be null for a root folder like Documents or Temporary. | |
| 28 | 28 | * This property is readonly. | |
| 29 | 29 | */ | |
@@ -67,6 +67,11 @@ export class File extends FileSystemEntity { | |||
| 67 | 67 | */ | |
| 68 | 68 | extension: string; | |
| 69 | 69 | ||
| 70 | + /** | ||
| 71 | + * Gets the size in bytes of the file. | ||
| 72 | + */ | ||
| 73 | + size: number; | ||
| 74 | + | ||
| 70 | 75 | /** | |
| 71 | 76 | * Gets a value indicating whether the file is currently locked, meaning a background operation associated with this file is running. | |
| 72 | 77 | */ | |
@@ -208,7 +213,7 @@ export module knownFolders { | |||
| 208 | 213 | * iOS - this folder is read-only and contains the app and all its resources. | |
| 209 | 214 | */ | |
| 210 | 215 | export function currentApp(): Folder; | |
| 211 | - | ||
| 216 | + | ||
| 212 | 217 | /** | |
| 213 | 218 | * Contains iOS-specific known folders. | |
| 214 | 219 | */ | |
@@ -217,42 +222,42 @@ export module knownFolders { | |||
| 217 | 222 | * Gets the NSLibraryDirectory. | |
| 218 | 223 | */ | |
| 219 | 224 | export function library(): Folder; | |
| 220 | - | ||
| 225 | + | ||
| 221 | 226 | /** | |
| 222 | 227 | * Gets the NSDeveloperDirectory. | |
| 223 | 228 | */ | |
| 224 | 229 | export function developer(): Folder; | |
| 225 | - | ||
| 230 | + | ||
| 226 | 231 | /** | |
| 227 | 232 | * Gets the NSDesktopDirectory. | |
| 228 | 233 | */ | |
| 229 | 234 | export function desktop(): Folder; | |
| 230 | - | ||
| 235 | + | ||
| 231 | 236 | /** | |
| 232 | 237 | * Gets the NSDownloadsDirectory. | |
| 233 | 238 | */ | |
| 234 | 239 | export function downloads(): Folder; | |
| 235 | - | ||
| 240 | + | ||
| 236 | 241 | /** | |
| 237 | 242 | * Gets the NSMoviesDirectory. | |
| 238 | 243 | */ | |
| 239 | 244 | export function movies(): Folder; | |
| 240 | - | ||
| 245 | + | ||
| 241 | 246 | /** | |
| 242 | 247 | * Gets the NSMusicDirectory. | |
| 243 | 248 | */ | |
| 244 | 249 | export function music(): Folder; | |
| 245 | - | ||
| 250 | + | ||
| 246 | 251 | /** | |
| 247 | 252 | * Gets the NSPicturesDirectory. | |
| 248 | 253 | */ | |
| 249 | 254 | export function pictures(): Folder; | |
| 250 | - | ||
| 255 | + | ||
| 251 | 256 | /** | |
| 252 | 257 | * Gets the NSSharedPublicDirectory. | |
| 253 | 258 | */ | |
| 254 | 259 | export function sharedPublic(): Folder; | |
| 255 | - } | ||
| 260 | + } | ||
| 256 | 261 | } | |
| 257 | 262 | ||
| 258 | 263 | /** | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -200,6 +200,10 @@ export class File extends FileSystemEntity { | |||
| 200 | 200 | return !!this._locked; | |
| 201 | 201 | } | |
| 202 | 202 | ||
| 203 | + get size(): number { | ||
| 204 | + return getFileAccess().getFileSize(this.path); | ||
| 205 | + } | ||
| 206 | + | ||
| 203 | 207 | public readSync(onError?: (error: any) => any): any { | |
| 204 | 208 | this.checkAccess(); | |
| 205 | 209 | ||
@@ -304,7 +308,7 @@ export class File extends FileSystemEntity { | |||
| 304 | 308 | onError(error); | |
| 305 | 309 | } | |
| 306 | 310 | }; | |
| 307 | - | ||
| 311 | + | ||
| 308 | 312 | // TODO: Asyncronous | |
| 309 | 313 | getFileAccess().writeText(this.path, content, localError, encoding); | |
| 310 | 314 | } finally { | |
@@ -499,15 +503,15 @@ export module knownFolders { | |||
| 499 | 503 | ||
| 500 | 504 | return _app; | |
| 501 | 505 | }; | |
| 502 | - | ||
| 506 | + | ||
| 503 | 507 | export module ios { | |
| 504 | 508 | function _checkPlatform(knownFolderName: string){ | |
| 505 | 509 | ensurePlatform(); | |
| 506 | 510 | if (!platform.isIOS){ | |
| 507 | 511 | throw new Error(`The "${knownFolderName}" known folder is available on iOS only!`); | |
| 508 | - } | ||
| 512 | + } | ||
| 509 | 513 | } | |
| 510 | - | ||
| 514 | + | ||
| 511 | 515 | let _library: Folder; | |
| 512 | 516 | export var library = function(): Folder { | |
| 513 | 517 | _checkPlatform("library"); | |
@@ -523,7 +527,7 @@ export module knownFolders { | |||
| 523 | 527 | ||
| 524 | 528 | return _library; | |
| 525 | 529 | }; | |
| 526 | - | ||
| 530 | + | ||
| 527 | 531 | let _developer: Folder; | |
| 528 | 532 | export var developer = function(): Folder { | |
| 529 | 533 | _checkPlatform("developer"); | |
@@ -539,7 +543,7 @@ export module knownFolders { | |||
| 539 | 543 | ||
| 540 | 544 | return _developer; | |
| 541 | 545 | }; | |
| 542 | - | ||
| 546 | + | ||
| 543 | 547 | let _desktop: Folder; | |
| 544 | 548 | export var desktop = function(): Folder { | |
| 545 | 549 | _checkPlatform("desktop"); | |
@@ -555,7 +559,7 @@ export module knownFolders { | |||
| 555 | 559 | ||
| 556 | 560 | return _desktop; | |
| 557 | 561 | }; | |
| 558 | - | ||
| 562 | + | ||
| 559 | 563 | let _downloads: Folder; | |
| 560 | 564 | export var downloads = function(): Folder { | |
| 561 | 565 | _checkPlatform("downloads"); | |
@@ -571,7 +575,7 @@ export module knownFolders { | |||
| 571 | 575 | ||
| 572 | 576 | return _downloads; | |
| 573 | 577 | }; | |
| 574 | - | ||
| 578 | + | ||
| 575 | 579 | let _movies: Folder; | |
| 576 | 580 | export var movies = function(): Folder { | |
| 577 | 581 | _checkPlatform("movies"); | |
@@ -587,7 +591,7 @@ export module knownFolders { | |||
| 587 | 591 | ||
| 588 | 592 | return _movies; | |
| 589 | 593 | }; | |
| 590 | - | ||
| 594 | + | ||
| 591 | 595 | let _music: Folder; | |
| 592 | 596 | export var music = function(): Folder { | |
| 593 | 597 | _checkPlatform("music"); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments