本文整理匯總了TypeScript中file-system.File類的典型用法代碼示例。如果您正苦於以下問題:TypeScript File類的具體用法?TypeScript File怎麽用?TypeScript File使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了File類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: 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();
}
示例2: 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();
}
示例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);
});
};
示例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}.`));
}
}
示例5: 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;
}
示例6: 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}.`));
}
}
示例7: 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;
}
示例8: 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);
})
}
示例9: 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();
}
}
}
示例10: constructor
constructor(protected path: string) {
if (path.indexOf("~/") === 0) {
this.path = path = fs.path.join(fs.knownFolders.currentApp().path, path.replace("~/", ""));
}
const documents = fs.knownFolders.currentApp();
console.log('folder:', documents.path);
fs.Folder.fromPath(fs.path.join(documents.path, '')).eachEntity(function (entity) {
console.log('-', entity.name);
// Return true to continue, or return false to stop the iteration.
return true;
});
if (!fs.File.exists(path)) {
console.error("Sound not initialized; file not found.");
return;
}
};