1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038
|
/*
* Licensed to OMTP Ltd. (OMTP) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information regarding
* copyright ownership.
*
* The Reference Implementation (save for such parts of the reference implementation made
* available under separate terms and conditions) is made available under the terms of the
* Apache License, version 2.0, subject to the condition that any "Works" and "Derivative
* Works" used or distributed for commercial purposes must be and remain compliant with the
* BONDI specification as promulgated by OMTP in each release. Your implementation of the
* Reference Implementation (whether object or source) must maintain these conditions, and
* you must notify any recipient of this condition in a conspicuous way.
*
* You may not use this BONDI Reference Implementation except in compliance with the License.
*
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 or at
* http://bondi.omtp.org/BONDI-LICENSE-2.0
*/
/**
* \brief BONDI filesystem API.
*
* The BONDI filesystem API provides access to the filesystem of a device. The
* filesystem is abstractly represented as a collection of disjoint filesystem
* root locations each corresponding to some specific location in the device
* filesystem. The filesystem API exposes the hierarchies below these root
* locations as a single virtual filesystem but provides no access to other
* parts of the device filesystem.
*
* The roots that are exposed are determined by the platform also by the
* context in which the filesystem API is invoked.
*
* Each root has a string name. Each file or directory within the virtual
* filesystem is addressed using a fully-qualified path of the form:
* <em><root name>/<path></em> where <em><rootname></em> is
* the name of the root and <em><path></em> is the path to the file or
* directory relative to that root.
*
* The list of the supported root locations can be retrieved by calling
* filesystem.getRootLocations().
*
* The default location for a specific type of file, if one exists, can be
* obtained by calling the filesystem.getDefaultLocation(...) method. A set of
* platform-independent symbolic names for media types is defined. The default
* location for a given file type may itself be a root, or some subdirectory of
* a root. Although the set of roots available on a device is
* platform-dependent, the getDefaultLocation(...) functionality can be used to
* ensure that web applications can be written in a platform-independent way.
*
* In order to access specific locations which are prefixed with a value
* retrieved by filesystem.getDefaultLocation or some root location returned by
* filesystem.getRootLocations a File handle must be retrieved using the
* filesystem.resolve call.
*
* A File handle represents either a file or a directory. If it is a file the
* isFile attribute will be <em>true</em>, otherwise the isDirectory attribute
* will be <em>true</em>. A file can be opened for reading and writing, using a
* FileStream handle. A directory can be used to list its contents which is a
* list of files and sub-directories. There is a resolve method on directories
* as well in order to resolve files or sub-directories more conveniently than
* processing directory listings.
*
* The "/" character is used as the (path) component separator.
* The use of "." or ".." in location components is not required to be
* supported.
*
* All path characters need to be <a href="http://www.ietf.org/rfc/rfc2279.txt">UTF-8</a> encoded.
*
* \code
* function errorCB(err) {
* alert("BONDI filesystem API couldn't be requested: " + err.message);
* }
*
* function successCB() {
* var docLocation = bondi.filesystem.getDefaultLocation("documents");
* var docDir = bondi.filesystem.resolve(docLocation);
* var docFiles = docDir.listFiles();
* for(var i = 0; i < docFiles.length; i++) {
* // displays name of each image file in image directory
* alert(docFiles[i].name);
* }
* var testFile = docDir.createFile("test.txt");
* var out = testFile.open("w", "UTF-8");
* // writes Hello World to test.txt
* out.write("Hello World");
* out.close();
* }
*
* bondi.requestFeature(successCB, errorCB, "filesystem");
* \endcode
*
* \def-api-feature http://bondi.omtp.org/api/filesystem.read
* \brief Filesystem read operations, including reading directory listings,
* file contents and resolving root locations.
* \device-cap io.file.read
*
* \def-api-feature http://bondi.omtp.org/api/filesystem.write
* \brief Filesystem write operations, including creating files/directories,
* writing to files, deleting files/directories, moving and copying
* files.
* \device-cap io.file.write
*
* \def-api-feature-set http://bondi.omtp.org/api/filesystem
* \brief All the FileSystem features
* \api-feature http://bondi.omtp.org/api/filesystem.read
* \api-feature http://bondi.omtp.org/api/filesystem.write
*
* \def-device-cap io.file.read
* \brief Read directory or file
* \param name Name of directory or file, in virtual filesystem,
* e.g. rootlocation/filename
*
* \def-device-cap io.file.write
* \brief Write directory or file
* \param name Name of directory or file, in virtual filesystem,
* e.g. rootlocation/filename
*
* \author Paddy Byers <paddy@aplixcorp.com>
* \author Anselm R Garbe <anselm@aplixcorp.com>
* \version 1.1
*/
module filesystem {
/**
* \brief Array of File handles.
*
* This array type is returned when directory listings are requested.
*/
typedef sequence<File> FileArray;
/**
* \brief File system specific success callback.
*
* This callback interface specifies a success callback with a function
* taking a File object as input argument. It is used in asynchronous
* operations such as copying, moving and deleting files.
*/
[Callback=FunctionOnly, NoInterfaceObject] interface FileSystemSuccessCallback {
/**
* \brief Method invoked when the asynchronous call completes succesfully
*
* \param file The file resulting from the asynchronous call
*/
void onSuccess(in File file);
};
/**
* \brief Manager class exposed as the filesystem modules API.
*
* This manager class exposes the filesystem base API, such as
* determining root and default locations, resolving a given location
* into a File Handle and registering filesystem listeners for
* filesystem events.
*
* \code
* function errorCB(err) {
* alert("BONDI filesystem API couldn't be requested: " + err.message);
* }
*
* function successCB() {
* var docLocation = bondi.filesystem.getDefaultLocation("documents");
* var docDir = bondi.filesystem.resolve(docLocation);
* var docFiles = docDir.listFiles();
* for(var i = 0; i < docFiles.length; i++) {
* // displays name of each image file in image directory
* alert(docFiles[i].name);
* }
* var testFile = docDir.createFile("test.txt");
* var out = testFile.open("w", "UTF-8");
* // writes Hello World to test.txt
* out.write("Hello World");
* out.close();
* }
*
* bondi.requestFeature(successCB, errorCB, "filesystem");
* \endcode
*/
interface FileSystemManager {
/**
* \brief Contains the platform-dependent maximum path length.
*
* Read-only.
*
* \code
* alert(bondi.filesystem.maxPathLength);
* \endcode
*/
readonly attribute unsigned long maxPathLength;
/**
* \brief Returns a default location path for the given arguments,
* including the root location prefix.
*
* Optionally this method can be called with the space argument
* specifying the minimum free disk space required.
*
* This function resolves location specifiers to location paths.
* The following location specifiers are supported:
* \n "wgt:package" the widget package location
* \n "wgt:private" the widgets private storage
* \n "wgt:public" the widgets public storage
* \n "wgt:temp" the widgets temporary storage
* \n "documents" the documents location,
* e.g. the "My Documents" directory on some systems
* \n "images" the images location,
* e.g. the "My Pictures" directory on some systems
* \n "videos" the videos location,
* e.g. the "My Videos" directory on some systems
* \n "temp" the temporary storage,
* e.g resolving to "Temp"
* \n "sdcard" the sdcard storage, if any
*
* \code
* var wgtLocation = bondi.filesystem.getDefaultLocation('wgt:package');
* \endcode
*
* \param specifier the location specifier, see above for supported specifiers.
* \param minFreeSpace optional, minimum required free disk space in bytes for
* this location, <em>0</em> (default) means no limitation
* \return the location as a string or <em>null</em> if there
* is no location for the given specifier or if there is not
* enough space left for the requested space in bytes.
* \throw DeviceAPIError INVALID_ARGUMENT_ERROR if the
* specifier or space arguments are invalid
*/
DOMString getDefaultLocation(in DOMString specifier, in unsigned long minFreeSpace)
raises(DeviceAPIError);
/**
* \brief Returns all root locations.
*
* The root locations are symbolic names for filesystem
* locations which are accessible and supported by the
* underlying platform.
*
* Usually the following root locations will be supported:
* \n "documents" represents "My Documents" on some platforms
* \n "images" represents "My Pictures" on some platforms
* \n "videos" represents "My Videos" on some platforms
* \n "temp" represents "tmp" on some platforms
* \n "sdcard" represents the sdcard on some platforms
*
* See also the getDefaultLocation method.
*
* \code
* var locations = bondi.filesystem.getRootLocations();
* for(var i = 0; i < locations.length; i++) {
* // locations[i] is a resolvable root location
* }
* \endcode
*
* \return string array of root locations.
*/
StringArray getRootLocations();
/**
* \brief Resolves a location to a File handle.
*
* Validates and resolves the given location to a File handle
* and returns a handle. A valid location is prefixed with a
* valid root or default location and must address an existing
* and accessible file.
*
* \api-feature http://bondi.omtp.org/api/filesystem.read
*
* \code
* var location = bondi.filesystem.getDefaultLocation("temp");
* var temp = bondi.filesystem.resolve(location);
* var documents = bondi.filesystem.getDefaultLocation("documents");
* var mydoc = bondi.filesystem.resolve(documents + "/data/2009/mydoc.txt");
* \endcode
*
* \param location the location to resolve. Must be absolute
* prefixed by a valid root or default location.
* \return the resolved file object.
* \throw SecurityError PERMISSION_DENIED_ERROR when
* access is denied by the security policy.
* \throw DeviceAPIError INVALID_ARGUMENT_ERROR if invalid location was given.
*/
File resolve(in DOMString location)
raises(SecurityError, DeviceAPIError);
/**
* \brief Registers a filesystem event listener.
*
* Filesystem event listeners are used in order to retrieve
* notifications if root or default locations such as storage
* cards are mounted/unmounted into/from the device filesystem.
*
* \api-feature http://bondi.omtp.org/api/filesystem.read
*
* \code
* var listener = { mountEvent: function(location) { alert('mounted ' + location); },
* unmountEvent: function(location) { alert('unmounted ' + location); };
* bondi.filesystem.registerEventListener(listener);
* \endcode
*
* \param listener the listener interface implementation
* \throw DeviceAPIError INVALID_ARGUMENT_ERROR if the given listener
* is invalid or not a listener.
*/
void registerEventListener(in FileSystemListener listener)
raises(DeviceAPIError);
/**
* \brief Unregisters a filesystem event listener.
*
* \code
* bondi.filesystem.unregisterEventListener(listener);
* \endcode
*
* \param listener the listener interface implementation
* \throw DeviceAPIError INVALID_ARGUMENT_ERROR if the given listener
* is invalid or not a listener.
*/
void unregisterEventListener(in FileSystemListener listener)
raises(DeviceAPIError);
};
/**
* \brief Filesystem event listener class.
*
* This listener implements two methods to retrieve mount and unmount
* notifications if root or default locations on a storage card get
* available or unavailable.
*
* \code
* var fsEventImpl = {
* mountEvent: function(location) {
* // location has been mounted
* },
* unmountEvent: function(location) {
* // location has been unmounted
* }
* };
* \endcode
*/
interface FileSystemListener {
/**
* \brief Called when a new root location gets available.
*
* A new location could be a storage card for example.
*
* \param location the newly available location
*/
void mountEvent(in DOMString location);
/**
* \brief Called when a location gets unavailable.
*
* Such a location could be a storage card for example.
*
* \param location the location which is becoming unavailable
*/
void unmountEvent(in DOMString location);
};
/**
* \brief File class.
*
* This interface represents the file abstraction in use. A file handle
* can address files or directories. A file handle represents a file
* if the isFile property is <em>true</em>, otherwise it represents a
* directory.
*
* A file handle representing a file can be opened for I/O operations
* such as reading and writing.
*
* A file handle representing a directory can list all files in the
* current directory.
*
* \code
*
* // list directory contents
* var files = dir.listFiles();
* for(var i = 0; i < files.length; i++) {
* // alerts each name of dir's contents
* alert(files[i].name);
* }
*
* // opens a file for writing
* var file = dir.createFile("test.txt");
* var out = file.open("w", "UTF-8");
* // writes Hello World to test.txt
* out.write("Hello World");
* out.close();
* \endcode
*/
interface File {
/**
* \brief Parent directory handle.
*
* Read-only.
*
* <em>null</em> if there is no parent directory.
*
* If there is no parent directory, this represents a root location.
*
* \code
* var parent = file.parent;
* if(parent != null) {
* // parent directory handle
* }
* \endcode
*/
readonly attribute File parent;
/**
* \brief File/directory access state in the filesystem.
*
* Read-only.
*
* <em>false</em> if there is write access.
*
* This attribute represents the actual state of a
* file/directory in the filesystem. It does not check if the
* accessor has io.file.write permission.
*
* \code
* if(file.readOnly) {
* // file cannot be written
* }
* \endcode
*/
readonly attribute boolean readOnly;
/**
* \brief File type.
*
* Read-only.
*
* <em>true</em> if this handle is a file.
* <em>false</em> if this handle is a directory.
*
* \code
* if(file.isFile) {
* // is a file
* }
* \endcode
*/
readonly attribute boolean isFile;
/**
* \brief File type.
*
* Read-only.
*
* <em>true</em> if this handle is a directory.
* <em>false</em> if this handle is a file.
*
* \code
* if(file.isDirectory) {
* // is a directory
* }
* \endcode
*/
readonly attribute boolean isDirectory;
/**
* \brief Creation timestamp.
*
* Read-only.
*
* The creation timestamp of this file. This is the timestamp
* when the file was first created in the filesystem. This is
* equivalent to the timestamp when a call to createFile()
* succeeds.
*
* It is unspecified and platform-dependent if the creation
* timestamp changes when a file is moved.
*
* \code
* alert(file.created); // displays the creation timestamp
* \endcode
*
*/
readonly attribute Date created;
/**
* \brief Modification timestamp.
*
* Read-only.
*
* The modification timestamp of this file. This is the timestamp
* of the most recent modification to the file, usually when the last
* write operation succeeded. Opening a file for reading does not change
* the modification timestamp.
*
* \code
* alert(file.modified); // displays the modification timestamp
* \endcode
*
*/
readonly attribute Date modified;
/**
* \brief Path of this file, excluding the file name.
*
* Read-only.
*
* If the file path is <em>/baz/foo.bar</em>, then
* the path is <em>/baz/</em>.
*
* The encoding of file paths is <a href="http://www.ietf.org/rfc/rfc2279.txt">UTF-8</a>.
*
* \code
* alert(file.path); // should be /baz/ if the file is /baz/foo.bar
* \endcode
*/
readonly attribute DOMString path;
/**
* \brief File name, excluding any path components.
*
* Read-only.
*
* Assumed the file path is <em>/baz/foo.bar</em>, then
* the file name is <em>foo.bar</em>.
*
* The encoding of file names is <a href="http://www.ietf.org/rfc/rfc2279.txt">UTF-8</a>.
*
* \code
* alert(file.name); // should be foo.bar if the file path is /baz/foo.bar
* \endcode
*/
readonly attribute DOMString name;
/**
* \brief Absolute path of this file.
*
* Read-only.
*
* Assumed the file path is <em>/baz/foo.bar</em>, then this is the absolute path.
*
* The encoding of file paths is <a href="http://www.ietf.org/rfc/rfc2279.txt">UTF-8</a>.
*
* \code
* alert(file.absolutePath); // should be /baz/foo.bar if the file is /baz/foo.bar
* \endcode
*/
readonly attribute DOMString absolutePath;
/**
* \brief Size in bytes of this file.
*
* Read-only.
*
* If it is attempted to read this attribute on a directory,
* <em>undefined</em> is returned.
*
* \code
* alert(file.fileSize); // displays the file size
* \endcode
*/
readonly attribute unsigned long fileSize;
/**
* \brief Files metadata.
*
* The actual map contents are implementation dependent.
*
* \code
* // should display the file author, if supported by the
* // platform, undefined otherwise
* alert(file.metadata.author);
* \endcode
*/
readonly attribute Map metadata;
/**
* \brief Returns list of all files of this directory.
*
* The list of files contains directories and files, it does
* not contain the directories "." and "..".
*
* \api-feature http://bondi.omtp.org/api/filesystem.read
*
* \code
* var files = dir.listFiles();
* for(var i = 0; i < files.length; i++) {
* // files[i] iterate over all files of this directory
* }
* \endcode
*
* \return array of contents of this directory.
* \throw SecurityError PERMISSION_DENIED_ERROR when
* access is denied by the security policy.
* \throw DeviceAPIError IO_ERROR if this is not a directory.
*/
FileArray listFiles()
raises(SecurityError, DeviceAPIError);
/**
* \brief Opens the file in the given mode supporting the given
* encoding.
*
* \api-feature http://bondi.omtp.org/api/filesystem.read
* \api-feature http://bondi.omtp.org/api/filesystem.write
*
* \code
* // opens file for reading
* var in = file.open("r", "UTF-8");
* \endcode
*
* \param mode the mode for opening a file
* \n "r" for reading
* \n "a" for appending
* \n "w" for [over]writing
* \param encoding the encoding for read/write operations on the file,
* supported encodings are:
* \n "<a href="http://www.ietf.org/rfc/rfc2279.txt">UTF-8</a>" default encoding
* \n "<a href="http://en.wikipedia.org/wiki/ISO/IEC_8859-1">ISO8859-1</a>" latin1 encoding
* \return file stream handle to read/write from/to.
* \throw SecurityError PERMISSION_DENIED_ERROR when
* access is denied by the security policy.
* \throw DeviceAPIError INVALID_ARGUMENT_ERROR if invalid mode
* or unsupported encoding is supplied.
* \throw DeviceAPIError IO_ERROR if this is not a file.
*/
FileStream open(in DOMString mode, in DOMString encoding)
raises(SecurityError, DeviceAPIError);
/**
* \brief Copies this file.
*
* The copy will be created in the given path. If this function
* fails and the error callback is called, it will pass an
* DeviceAPIError IO_ERROR to the callback.
*
* The encoding of file paths is <a href="http://www.ietf.org/rfc/rfc2279.txt">UTF-8</a>.
*
* \api-feature http://bondi.omtp.org/api/filesystem.write
*
* \code
* // copies this file to /temp/file.copy
* var op = file.copyTo(function(copiedFile) { alert("file copied"); }, null, "/temp/file.copy", false);
* \endcode
*
* \param successCallback called when the file has been copied.
* \param errorCallback called if an error occured.
* \param filePath the new file path, [a-Z0-9_- /]+ are allowed
* \param overwrite <em>true</em> enforces overwriting an existing file.
* \return PendingOperation enabling the requester to cancel this request.
* \throw SecurityError PERMISSION_DENIED_ERROR when
* access is denied by the security policy.
* \throw DeviceAPIError IO_ERROR if it is attempted to move to a directory.
* \throw DeviceAPIError IO_ERROR if overwrite is <em>false</em> and target file exists.
* \throw DeviceAPIError IO_ERROR if any characters in the path are not supported.
* \throw DeviceAPIError IO_ERROR if the file cannot be copied.
*/
PendingOperation copyTo(in FileSystemSuccessCallback successCallback,
in ErrorCallback errorCallback,
in DOMString filePath,
in boolean overwrite)
raises(SecurityError, DeviceAPIError);
/**
* \brief Moves this file.
*
* The file will be moved atomically to the given path. This is
* different to copyTo and deleting the old file, because this
* operation does not need extra disk space on certain platforms.
* If this function fails and the error callback is called, it
* will pass an DeviceAPIError IO_ERROR to the callback.
*
* The encoding of file paths is <a href="http://www.ietf.org/rfc/rfc2279.txt">UTF-8</a>.
*
* \api-feature http://bondi.omtp.org/api/filesystem.write
*
* \code
* // moves this file to /temp/file.move
* var op = file.moveTo(function(movedFile) { file = movedFile; }, null, "/temp/file.move");
* \endcode
*
* \param successCallback called when the file has been copied.
* \param errorCallback called if an error occured.
* \param filePath the new file name, [a-Z0-9_- /]+ are allowed
* \param overwrite <em>true</em> enforces overwriting an existing file.
* \return PendingOperation enabling the requester to cancel this request.
* \throw SecurityError PERMISSION_DENIED_ERROR when
* access is denied by the security policy.
* \throw DeviceAPIError IO_ERROR if it is attempted to move to a directory.
* \throw DeviceAPIError IO_ERROR if overwrite is <em>false</em> and target file exists.
* \throw DeviceAPIError IO_ERROR if any characters in the path are not supported.
* \throw DeviceAPIError IO_ERROR if the file cannot be moved.
*/
PendingOperation moveTo(in FileSystemSuccessCallback successCallback,
in ErrorCallback errorCallback,
in DOMString filePath,
in boolean overwrite)
raises(SecurityError, DeviceAPIError);
/**
* \brief Creates a directory.
*
* The new directory will be created relatively to the current
* directory this operation is performed on. It will attempt to
* create all necessary sub-directories as well. The use of "."
* or ".." in path components is not supported. If the
* bottom-most directory being created already exists this
* method will throw an IO_ERROR.
*
* The encoding of file paths is <a href="http://www.ietf.org/rfc/rfc2279.txt">UTF-8</a>.
*
* \api-feature http://bondi.omtp.org/api/filesystem.write
*
* \code
* var newDir = dir.createDirectory("newDir");
* var anotherNewDir = dir.createDirectory("newDir1/subNewDir1");
* \endcode
*
* \param dirPath the new directory path, it should only contain
* characters supported by the underlying filesystem.
* \return file handle of the new directory
* \throw SecurityError PERMISSION_DENIED_ERROR when
* access is denied by the security policy.
* \throw DeviceAPIError IO_ERROR if this is not a directory.
* \throw DeviceAPIError IO_ERROR if any path component does not exist.
* \throw DeviceAPIError IO_ERROR if a file with the same name exists.
* \throw DeviceAPIError IO_ERROR if any characters in the path are not supported.
* \throw DeviceAPIError IO_ERROR if the directory cannot be created.
*/
File createDirectory(in DOMString dirPath)
raises(SecurityError, DeviceAPIError);
/**
* \brief Creates a new empty file.
*
* The new empty file is created in the given path relatively
* to the current directory the operation is performed on. The
* use of "." or ".." in path components is not supported. If
* the bottom-most file being created already exists this
* method will throw an IO_ERROR. If any path component does
* not exist this method will throw an IO_ERROR.
*
* The encoding of file paths is <a href="http://www.ietf.org/rfc/rfc2279.txt">UTF-8</a>.
*
* \api-feature http://bondi.omtp.org/api/filesystem.write
*
* \code
* var newFile = dir.createFile("newFile");
* \endcode
*
* \param filePath the new file path, it should only contain
* characters supported by the underlying filesystem.
* \return file handle of the new empty file
* \throw SecurityError PERMISSION_DENIED_ERROR when
* access is denied by the security policy.
* \throw DeviceAPIError IO_ERROR if this is not a directory.
* \throw DeviceAPIError IO_ERROR if any path component does not exist.
* \throw DeviceAPIError IO_ERROR if the file already exists.
* \throw DeviceAPIError IO_ERROR if any characters in the path are not supported.
* \throw DeviceAPIError IO_ERROR if the file cannot be created.
*/
File createFile(in DOMString filePath)
raises(SecurityError, DeviceAPIError);
/**
* \brief Resolves an existing file or directory relatively to
* the current directory this operation is performed on; and
* returns a file handle for it.
*
* The filePath is not allowed to contain the "." or ".." directories.
*
* The encoding of file paths is <a href="http://www.ietf.org/rfc/rfc2279.txt">UTF-8</a>.
*
* \api-feature http://bondi.omtp.org/api/filesystem.read
*
* \code
* var hellofile = dir.resolve("foo/hello.txt");
* \endcode
*
* \param filePath the relative file/directory path to resolve.
* \return file handle of the file or <em>null</em> if it cannot be resolved.
* \throw SecurityError PERMISSION_DENIED_ERROR when
* access is denied by the security policy.
* \throw DeviceAPIError IO_ERROR if this is not a directory.
* \throw DeviceAPIError IO_ERROR if any characters in the path are not supported.
* \throw DeviceAPIError IO_ERROR if the file or directory cannot be resolved.
*/
File resolve(in DOMString filePath)
raises(SecurityError, DeviceAPIError);
/**
* \brief Deletes this directory.
*
* This function attempts to delete a directory or directory
* tree synchronously and returns <em>true</em> on success,
* <em>false</em> otherwise. It may throw an IO_ERROR if a
* recursive deletion partially fails and any deleted data so
* far cannot be recovered. This might happen due the lack of
* filesystem permissions or if any directories or files are
* openened by other processes.
*
* \api-feature http://bondi.omtp.org/api/filesystem.write
*
* \code
* var fullPath = dir.fullPath;
* if(dir.deleteDirectory(true)) {
* // subsequent accesses to dir will throw an error
* alert(fullPath + ' deleted');
* }
* \endcode
*
* \param recursive <em>true</em> means a recursive deletion, this
* will destroy all data recursively, use with caution.
* \return <em>true</em> on success
* \throw SecurityError PERMISSION_DENIED_ERROR when
* access is denied by the security policy.
* \throw DeviceAPIError IO_ERROR if this is a file.
* \throw DeviceAPIError IO_ERROR if the directory is not empty and
* this operation is not performed recursively.
* \throw DeviceAPIError IO_ERROR if the directory or any file or sub-directory cannot be deleted.
*/
boolean deleteDirectory(in boolean recursive)
raises(SecurityError, DeviceAPIError);
/**
* \brief Deletes this file.
*
* Returns <em>true</em> on success, <em>false</em> otherwise.
*
* \api-feature http://bondi.omtp.org/api/filesystem.write
*
* \code
* var fullPath = dir.fullPath;
* if(dir.deleteFile()) {
* // subsequent accesses to dir will throw an error
* alert(fullPath + ' deleted');
* }
* \endcode
*
* \return <em>true</em> on success
* \throw SecurityError PERMISSION_DENIED_ERROR when
* access is denied by the security policy.
* \throw DeviceAPIError IO_ERROR if this is a directory.
* \throw DeviceAPIError IO_ERROR if the file cannot be deleted due
* the lack of filesystem permissions or if it is locked or
* opened by another process.
*/
boolean deleteFile()
raises(SecurityError, DeviceAPIError);
};
/**
* \brief FileStream API.
*
* A FileStream represents a handle to a File opened for read and/or
* write operations. Read and write operations are performed relative
* to a file pointer which represents the current position in the file.
*
* A series of read/write methods are available that permit both binary and
* text to be processed.
*
* Once a file stream is closed, any operation attempted on this stream
* will result in a normal JavaScript error.
*/
interface FileStream {
/**
* \brief Indicates whether or not the current file pointer is at the end
* of the file.
*
* <em>true</em> if the position is at the end of the current file stream.
*
* \code
* if(stream.eof) {
* // file has been read completely
* }
* \endcode
*/
readonly attribute boolean eof;
/**
* \brief Get/set stream position for reads/writes.
*
* The stream position is an offset of bytes from the start of
* the file stream. When invoking an operation that reads or
* writes from the stream, the operation will take place from
* the position in the position attribute.
*
* \code
* alert(stream.position); // displays current stream position
* // alters current stream position to the begin of the file,
* // like seek() in C
* stream.position = 0;
* \endcode
* \throw DeviceAPIError IO_ERROR if a position was given that is out of the stream range.
*/
attribute unsigned long position
setraises(DeviceAPIError);
/**
* \brief Returns the number of bytes that are available for
* reading from the stream.
*
* The number of bytes available for reading is the maximum
* amount of bytes that can be read in the next read operation.
*
* -1 if eof is <em>true</em>.
*
* \code
* alert(stream.bytesAvailable); // displays the available bytes to be read
* \endcode
*/
readonly attribute unsigned long bytesAvailable;
/**
* \brief Closes this FileStream.
*
* Flushes any pending buffered writes and closes the File. Always succeeds.
* Note that pending writes might not succeed.
*
* \code
* stream.close(); // closes this stream, no subsequent access to stream allowed
* \endcode
*/
void close();
/**
* \brief Reads the specified number of characters.
*
* Reads specified number of characters and returns them as string.
* The resulting string length might be shorter than charCount if eof
* is <em>true</em>.
*
* \code
* var text = stream.read(0);
* stream.close();
* \endcode
*
* \param charCount number of characters being read, if
* <em>0</em> it will read as long as bytes are available.
* \return the result of read characters as a string.
* \throw DeviceAPIError IO_ERROR if an error occurs during read.
*/
DOMString read(in unsigned long charCount)
raises(DeviceAPIError);
/**
* \brief Reads the specified number of bytes from this FileStream.
*
* If 0 is supplied it will read all available bytes in a
* single read operation.
*
* \code
* // reads up to 256 bytes from the stream
* var raw = stream.readBytes(256);
* for(var i = 0; i < raw.length; i++) {
* // raw[i] contains the i-th byte of the current data chunk
* }
* \endcode
*
* \param byteCount number of bytes being read. Must not be <em>0</em>.
* \return the result of read bytes as a byte (or number) array.
* \throw DeviceAPIError IO_ERROR if an error occurs during readBytes.
*/
ByteArray readBytes(in unsigned long byteCount)
raises(DeviceAPIError);
/**
* \brief Reads the specified number of bytes from this FileStream, encoding
* the result in base64.
*
* If 0 is supplied it will read all available bytes in a
* single read operation.
*
* \code
* // reads up to 256 bytes from the stream
* var base64 = stream.readBase64(256);
* \endcode
*
* \param byteCount number of bytes being read. Must not be <em>0</em>.
* \return the result of read bytes as base64 encoding string.
* \throw DeviceAPIError IO_ERROR if an error occurs during readBase64.
*/
DOMString readBase64(in unsigned long byteCount)
raises(DeviceAPIError);
/**
* \brief Writes the specified DOMString to this FileStream.
*
* \code
* var text = "Hello world";
* stream.write(text);
* \endcode
*
* \param stringData the actual string to be written.
* \throw DeviceAPIError IO_ERROR if an error occurs during write.
*/
void write(in DOMString stringData)
raises(DeviceAPIError);
/**
* \brief Writes the specified bytes to this FileStream.
*
* \code
* var bytes = in.readBytes(256);
* out.writeBytes(bytes); // writes the bytes read from in to out
* \endcode
*
* \param byteData the byte data array being written.
* \throw DeviceAPIError IO_ERROR if an error occurs during writeBytes.
*/
void writeBytes(in ByteArray byteData)
raises(DeviceAPIError);
/**
* \brief Converts the specified base64 DOMString to bytes and writes the
* result to this FileStream.
*
* \code
* var base64 = in.readBase64(256);
* out.writeBase64(base64); // writes the base64 data read from in to out
* \endcode
*
* \param base64Data the base64 data being written.
* \throw DeviceAPIError IO_ERROR if an error occurs during writeBase64.
*/
void writeBase64(in DOMString base64Data)
raises(DeviceAPIError);
};
/**
* \brief Specifies what is instantiated at feature request
* \def-instantiated
* \api-feature http://bondi.omtp.org/api/filesystem.read
* \api-feature http://bondi.omtp.org/api/filesystem.write
*/
interface FileSystemManagerObject {
readonly attribute FileSystemManager fileSystemManager;
};
bondi implements FileSystemManagerObject;
};
|