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


TypeScript file-system.File类代码示例

本文整理汇总了TypeScript中tns-core-modules/file-system.File的典型用法代码示例。如果您正苦于以下问题:TypeScript File类的具体用法?TypeScript File怎么用?TypeScript File使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: function

export var test_XmlParser_IntegrationTest = function () {
    var actualResult = "";
    var xmlParser = new xmlModule.XmlParser(function (event: xmlModule.ParserEvent) {
        if (event.eventType === xmlModule.ParserEventType.Text && event.data.trim() === "") {
            // Ignore ignorable whitespace.
            return;
        }

        actualResult += event.toString();
    });

    var file = fs.File.fromPath(fs.path.join(__dirname, "xml.xml"));
    var xmlString = file.readTextSync();
    xmlString = xmlString.replace(/(\r\n|\n|\r)/gm, "\n");
    xmlParser.parse(xmlString);

    var expectedResult: string;
    file = fs.File.fromPath(fs.path.join(__dirname, "xml.expected"));
    expectedResult = file.readTextSync();

    var i;
    var maxLength = Math.max(actualResult.length, expectedResult.length);
    for (i = 0; i < maxLength; i++) {

        var actualChar;
        var actualCharCode;
        if (i <= actualResult.length) {
            actualChar = actualResult.charAt(i);
            actualCharCode = actualResult.charCodeAt(i);
        }
        else {
            actualChar = "undefined";
            actualCharCode = "undefined";
        }

        var expectedChar;
        var expectedCharCode;
        if (i <= expectedResult.length) {
            expectedChar = expectedResult.charAt(i);
            expectedCharCode = expectedResult.charCodeAt(i);
        }
        else {
            expectedChar = "undefined";
            expectedCharCode = "undefined";
        }

        TKUnit.assert(actualCharCode === expectedCharCode, "At index " + i + ": Actual character is " + actualChar + "[" + actualCharCode + "]; Expected character is: " + expectedChar + "[" + expectedCharCode + "]");
    }
};
开发者ID:triniwiz,项目名称:NativeScript,代码行数:49,代码来源:xml-parser-tests.ts

示例2: testSaveToFile_WithQuality

export function testSaveToFile_WithQuality() {
    const img = imageSource.fromFile(imagePath);
    const folder = fs.knownFolders.documents();
    const path = fs.path.join(folder.path, "test.png");
    const saved = img.saveToFile(path, "png", 70);
    TKUnit.assert(saved, "Image not saved to file");
    TKUnit.assert(fs.File.exists(path), "Image not saved to file");
}
开发者ID:NathanWalker,项目名称:NativeScript,代码行数:8,代码来源:image-source-tests.ts

示例3: test_MultiParserTemplate

export function test_MultiParserTemplate() {
    const file = fs.File.fromPath(fs.path.join(__dirname, "itemTemplates.xml"));
    const xml = file.readTextSync();

    const view: any = builder.parse(xml);
    TKUnit.assertNotNull(view.items)
    TKUnit.assertEqual(view.items.length, 1);
}
开发者ID:triniwiz,项目名称:NativeScript,代码行数:8,代码来源:xml-parser-tests.ts

示例4: function

export var test_file_exists_on_folder = function () {
    var path = fs.path.join(__dirname, "folder");

    if (!fs.Folder.exists(path)) {
        TKUnit.assert(false, `Could not read path ${path}`);
        return;
    }

    TKUnit.assertTrue(fs.File.exists(path), "File.exists() returned false for folder!");
};
开发者ID:NathanWalker,项目名称:NativeScript,代码行数:10,代码来源:file-system-access-tests.ts

示例5: testSaveToFile

export function testSaveToFile() {
    // >> imagesource-save-to
    const img = imageSource.fromFile(imagePath);
    const folder = fs.knownFolders.documents();
    const path = fs.path.join(folder.path, "test.png");
    const saved = img.saveToFile(path, "png");
    // << imagesource-save-to
    TKUnit.assert(saved, "Image not saved to file");
    TKUnit.assert(fs.File.exists(path), "Image not saved to file");
}
开发者ID:NathanWalker,项目名称:NativeScript,代码行数:10,代码来源:image-source-tests.ts

示例6: testFromFile

export function testFromFile() {
    // >> imagesource-load-local
    const folder = fs.knownFolders.documents();
    const path = fs.path.join(folder.path, "test.png");
    const img = imageSource.fromFile(path);
    // << imagesource-load-local

    TKUnit.assert(img.height > 0, "image.fromResource failed");

    // remove the image from the file system
    const file = folder.getFile("test.png");
    file.remove();
    TKUnit.assert(!fs.File.exists(path), "test.png not removed");
}
开发者ID:NathanWalker,项目名称:NativeScript,代码行数:14,代码来源:image-source-tests.ts

示例7: Promise

  return new Promise((resolve, reject) => {
    try {

      const storageRef = getStorageRef(reject, arg);

      if (!storageRef) {
        return;
      }

      const storageReference = storageRef.child(arg.remoteFullPath);

      const onSuccessListener = new com.google.android.gms.tasks.OnSuccessListener({
        onSuccess: uploadTaskSnapshot => {
          const metadata = uploadTaskSnapshot.getMetadata();
          resolve({
            name: metadata.getName(),
            contentType: metadata.getContentType(),
            created: new Date(metadata.getCreationTimeMillis()),
            updated: new Date(metadata.getUpdatedTimeMillis()),
            bucket: metadata.getBucket(),
            size: metadata.getSizeBytes(),
            // url: metadata.getDownloadUrl().toString()
          });
        }
      });

      const onFailureListener = new com.google.android.gms.tasks.OnFailureListener({
        onFailure: exception => {
          reject("Upload failed. " + exception);
        }
      });

      const onProgressListener = new com.google.firebase.storage.OnProgressListener({
        onProgress: snapshot => {
          if (typeof(arg.onProgress) === "function") {
            const fractionCompleted = snapshot.getBytesTransferred() / snapshot.getTotalByteCount();
            arg.onProgress({
              fractionCompleted: fractionCompleted,
              percentageCompleted: Math.round(fractionCompleted * 100)
            });
          }
        }
      });

      if (arg.localFile) {
        if (typeof(arg.localFile) !== "object") {
          reject("localFile argument must be a File object; use file-system module to create one");
          return;
        }

        // using 'putFile' (not 'putBytes') so Firebase can infer the mimetype
        const localFileUrl = android.net.Uri.fromFile(new java.io.File(arg.localFile.path));
        storageReference.putFile(localFileUrl)
            .addOnFailureListener(onFailureListener)
            .addOnSuccessListener(onSuccessListener)
            .addOnProgressListener(onProgressListener);

        /*
        var error;
        var contents = arg.localFile.readSync(e => { error = e; });

        if (error) {
          reject("Error reading file " + arg.localFile + ": " + error);
          return;
        }

        var uploadDataTask = storageReference.putBytes(contents)
            .addOnFailureListener(onFailureListener)
            .addOnSuccessListener(onSuccessListener)
            .addOnProgressListener(onProgressListener);
        */

      } else if (arg.localFullPath) {

        if (!File.exists(arg.localFullPath)) {
          reject("File does not exist: " + arg.localFullPath);
          return;
        }

        const localFileUrl = android.net.Uri.fromFile(new java.io.File(arg.localFullPath));
        storageReference.putFile(localFileUrl)
            .addOnFailureListener(onFailureListener)
            .addOnSuccessListener(onSuccessListener)
            .addOnProgressListener(onProgressListener);

      } else {
        reject("One of localFile or localFullPath is required");
      }

    } catch (ex) {
      console.log("Error in firebase.uploadFile: " + ex);
      reject(ex);
    }
  });
开发者ID:NathanWalker,项目名称:nativescript-plugin-firebase,代码行数:94,代码来源:storage.android.ts

示例8: fileExists

 public fileExists(path: string): boolean {
     return File.exists(path);
 }
开发者ID:NathanWalker,项目名称:nativescript-angular,代码行数:3,代码来源:ns-file-system.ts


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