当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript File.fromPath方法代码示例

本文整理汇总了TypeScript中file-system.File.fromPath方法的典型用法代码示例。如果您正苦于以下问题:TypeScript File.fromPath方法的具体用法?TypeScript File.fromPath怎么用?TypeScript File.fromPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在file-system.File的用法示例。


在下文中一共展示了File.fromPath方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: get

    get(url: string): Promise<string> {
        const appDir = knownFolders.currentApp().path;
        const templatePath = this.resolve(url, appDir);

        if (!File.exists(templatePath)) {
            throw new Error(`File ${templatePath} does not exist. Resolved from: ${url}.`);
        }
        let templateFile = File.fromPath(templatePath);
        return templateFile.readText();
    }
开发者ID:AhmedRagheb,项目名称:nativescript-angular,代码行数:10,代码来源:xhr.ts

示例2: get

  get(url: string): Promise<string> {
      let appDir = knownFolders.currentApp().path;
      let templatePath = path.join(appDir, url);

      if (!File.exists(templatePath)) {
          throw new Error(`File ${url} does not exist.`);
      }
      let templateFile = File.fromPath(templatePath);
      return templateFile.readText();
  }
开发者ID:ImNitinNayar7,项目名称:nativescript-angular,代码行数:10,代码来源:xhr.ts

示例3: loadStyles

function loadStyles() {
    var path = fs.path.join(fs.knownFolders.currentApp().path, cssPath);

    if (!fs.File.exists(path)) {
        throw new Error("Could not find code-highlight.css. Lookup path: " + path);
    }

    style = fs.File.fromPath(path).readTextSync((error) => {
        console.log("Error loading style file: " + error);
    });
};
开发者ID:phattranky,项目名称:nativescript-marketplace-demo,代码行数:11,代码来源:code-page-view-model.ts

示例4: toFile

export function toFile(destinationFilePath:string, content:any) {
    const data = data = NSData.alloc().initWithBase64EncodedStringOptions(content, NSDataBase64DecodingOptions.NSDataBase64DecodingIgnoreUnknownCharacters);
    var fs:typeof fsModule = require("file-system");

    if (data instanceof NSData) {
        data.writeToFileAtomically(destinationFilePath, true);
        return fs.File.fromPath(destinationFilePath);
    } else {
        reject(new Error(`Cannot save file with path: ${destinationFilePath}.`));
    }
}
开发者ID:anhoev,项目名称:cms-mobile,代码行数:11,代码来源:to-file.ios.ts

示例5: require

 toFile: (destinationFilePath?: string) => {
     var fs: typeof fsModule = require("file-system");
     var fileName = options.url;
     if (!destinationFilePath) {
         destinationFilePath = fs.path.join(fs.knownFolders.documents().path, fileName.substring(fileName.lastIndexOf('/') + 1));
     }
     if (data instanceof NSData) {
         data.writeToFileAtomically(destinationFilePath, true);
         return fs.File.fromPath(destinationFilePath);
     } else {
         reject(new Error(`Cannot save file with path: ${destinationFilePath}.`));
     }
 }
开发者ID:Prettycode-KC,项目名称:NativeScript,代码行数:13,代码来源:http-request.ios.ts

示例6: selectFileEntity

    private selectFileEntity(entity: fs.FileSystemEntity) {
        this.set("isLoading", true);
        this.set("selectedFileName", entity.name);

        var codeFile = fs.File.fromPath(entity.path);
        var lang = extensionToLanguage[codeFile.extension];

        codeFile.readText().then((codeString) => {
            var formattedCode = hljs.highlight("javascript", codeString).value;
            formattedCode = hljs.fixMarkup(formattedCode);
            formattedCode = "<style>" + style + "</style><pre><code>" + formattedCode + "</pre></code>"

            this.set("isLoading", false);
            this.set("formattedCode", formattedCode);
        }, (error) => {
            this.set("isLoading", false);
            console.log("readText() error: " + error);
        })
    }
开发者ID:phattranky,项目名称:nativescript-marketplace-demo,代码行数:19,代码来源:code-page-view-model.ts

示例7: toFile

export function toFile(destinationFilePath:string, content:any) {
    const data = android.util.Base64.decode(content, android.util.Base64.DEFAULT);
    var fs:typeof fsModule = require("file-system");
    var stream:java.io.FileOutputStream;
    try {
        var javaFile = new java.io.File(destinationFilePath);
        stream = new java.io.FileOutputStream(javaFile);
        stream.write(data);
        return fs.File.fromPath(destinationFilePath);
    }
    catch (exception) {
        throw new Error(`Cannot save file with path: ${destinationFilePath}.`);
    }
    finally {
        if (stream) {
            stream.close();
        }
    }
}
开发者ID:anhoev,项目名称:cms-mobile,代码行数:19,代码来源:to-file.android.ts

示例8: loadCss

export function loadCss(cssFile?: string): Array<cssSelector.CssSelector> {
    if (!cssFile) {
        return undefined;
    }

    var result: Array<cssSelector.CssSelector>;

    var fs: typeof fileSystemModule = require("file-system");
    var styleScope: typeof styleScopeModule = require("ui/styling/style-scope");

    var cssFileName = fs.path.join(fs.knownFolders.currentApp().path, cssFile);
    if (fs.File.exists(cssFileName)) {
        var file = fs.File.fromPath(cssFileName);
        var applicationCss = file.readTextSync();
        if (applicationCss) {
            result = styleScope.StyleScope.createSelectorsFromCss(applicationCss, cssFileName);
        }
    }

    return result;
}
开发者ID:ImNitinNayar7,项目名称:NativeScript,代码行数:21,代码来源:application-common.ts

示例9: require

 toFile: (destinationFilePath?: string) => {
     var fs: typeof fsModule = require("file-system");
     var fileName = callbacks.url;
     if (!destinationFilePath) {
         destinationFilePath = fs.path.join(fs.knownFolders.documents().path, fileName.substring(fileName.lastIndexOf('/') + 1));
     }
     var stream: java.io.FileOutputStream;
     try {
         var javaFile = new java.io.File(destinationFilePath);
         stream = new java.io.FileOutputStream(javaFile);
         stream.write(result.raw.toByteArray());
         return fs.File.fromPath(destinationFilePath);
     }
     catch (exception) {
         throw new Error(`Cannot save file with path: ${destinationFilePath}.`);
     }
     finally {
         if (stream) {
             stream.close();
         }
     }
 }
开发者ID:Prettycode-KC,项目名称:NativeScript,代码行数:22,代码来源:http-request.android.ts

示例10: loadCss

export function loadCss(cssFile?: string): RuleSet[] {
    if (!cssFile) {
        return undefined;
    }

    var result: RuleSet[];

    var fs: typeof fileSystemModule = require("file-system");
    if (!styleScope) {
        styleScope = require("ui/styling/style-scope");
    }

    var cssFileName = fs.path.join(fs.knownFolders.currentApp().path, cssFile);
    if (fs.File.exists(cssFileName)) {
        var file = fs.File.fromPath(cssFileName);
        var applicationCss = file.readTextSync();
        if (applicationCss) {
            result = parseCss(applicationCss, cssFileName);
        }
    }

    return result;
}
开发者ID:CedarLogic,项目名称:NativeScript,代码行数:23,代码来源:application-common.ts


注:本文中的file-system.File.fromPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。