1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/webidl/Directory.webidl Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,105 @@ 1.4 +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.7 + * You can obtain one at http://mozilla.org/MPL/2.0/. 1.8 + */ 1.9 + 1.10 +interface File; 1.11 + 1.12 +/* 1.13 + * All functions on Directory that accept DOMString arguments for file or 1.14 + * directory names only allow relative path to current directory itself. The 1.15 + * path should be a descendent path like "path/to/file.txt" and not contain a 1.16 + * segment of ".." or ".". So the paths aren't allowed to walk up the directory 1.17 + * tree. For example, paths like "../foo", "..", "/foo/bar" or "foo/../bar" are 1.18 + * not allowed. 1.19 + */ 1.20 +[NoInterfaceObject] 1.21 +interface Directory { 1.22 + /* 1.23 + * The leaf name of the directory. 1.24 + */ 1.25 + readonly attribute DOMString name; 1.26 + 1.27 + /* 1.28 + * Creates a new file or replaces an existing file with given data. The file 1.29 + * should be a descendent of current directory. 1.30 + * 1.31 + * @param path The relative path of the new file to current directory. 1.32 + * @param options It has two optional properties, 'ifExists' and 'data'. 1.33 + * If 'ifExists' is 'fail' and the path already exists, createFile must fail; 1.34 + * If 'ifExists' is 'replace', the path already exists, and is a file, create 1.35 + * a new file to replace the existing one; 1.36 + * If 'ifExists' is 'replace', the path already exists, but is a directory, 1.37 + * createFile must fail. 1.38 + * Otherwise, if no other error occurs, createFile will create a new file. 1.39 + * The 'data' property contains the new file's content. 1.40 + * @return If succeeds, the promise is resolved with the new created 1.41 + * File object. Otherwise, rejected with a DOM error. 1.42 + */ 1.43 + [NewObject] 1.44 + // Promise<File> 1.45 + Promise createFile(DOMString path, optional CreateFileOptions options); 1.46 + 1.47 + /* 1.48 + * Creates a descendent directory. This method will create any intermediate 1.49 + * directories specified by the path segments. 1.50 + * 1.51 + * @param path The relative path of the new directory to current directory. 1.52 + * If path exists, createDirectory must fail. 1.53 + * @return If succeeds, the promise is resolved with the new created 1.54 + * Directory object. Otherwise, rejected with a DOM error. 1.55 + */ 1.56 + [NewObject] 1.57 + // Promise<Directory> 1.58 + Promise createDirectory(DOMString path); 1.59 + 1.60 + /* 1.61 + * Gets a descendent file or directory with the given path. 1.62 + * 1.63 + * @param path The descendent entry's relative path to current directory. 1.64 + * @return If the path exists and no error occurs, the promise is resolved 1.65 + * with a File or Directory object, depending on the entry's type. Otherwise, 1.66 + * rejected with a DOM error. 1.67 + */ 1.68 + [NewObject] 1.69 + // Promise<(File or Directory)> 1.70 + Promise get(DOMString path); 1.71 + 1.72 + /* 1.73 + * Deletes a file or an empty directory. The target must be a descendent of 1.74 + * current directory. 1.75 + * @param path If a DOM string is passed, it is the relative path of the 1.76 + * target. Otherwise, the File or Directory object of the target should be 1.77 + * passed. 1.78 + * @return If the target is a non-empty directory, or if deleting the target 1.79 + * fails, the promise is rejected with a DOM error. If the target did not 1.80 + * exist, the promise is resolved with boolean false. If the target did exist 1.81 + * and was successfully deleted, the promise is resolved with boolean true. 1.82 + */ 1.83 + [NewObject] 1.84 + // Promise<boolean> 1.85 + Promise remove((DOMString or File or Directory) path); 1.86 + 1.87 + /* 1.88 + * Deletes a file or a directory recursively. The target should be a 1.89 + * descendent of current directory. 1.90 + * @param path If a DOM string is passed, it is the relative path of the 1.91 + * target. Otherwise, the File or Directory object of the target should be 1.92 + * passed. 1.93 + * @return If the target exists, but deleting the target fails, the promise is 1.94 + * rejected with a DOM error. If the target did not exist, the promise is 1.95 + * resolved with boolean false. If the target did exist and was successfully 1.96 + * deleted, the promise is resolved with boolean true. 1.97 + */ 1.98 + [NewObject] 1.99 + // Promise<boolean> 1.100 + Promise removeDeep((DOMString or File or Directory) path); 1.101 +}; 1.102 + 1.103 +enum CreateIfExistsMode { "replace", "fail" }; 1.104 + 1.105 +dictionary CreateFileOptions { 1.106 + CreateIfExistsMode ifExists = "fail"; 1.107 + (DOMString or Blob or ArrayBuffer or ArrayBufferView) data; 1.108 +};