當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript File.readAsArrayBuffer方法代碼示例

本文整理匯總了TypeScript中@ionic-native/file.File.readAsArrayBuffer方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript File.readAsArrayBuffer方法的具體用法?TypeScript File.readAsArrayBuffer怎麽用?TypeScript File.readAsArrayBuffer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@ionic-native/file.File的用法示例。


在下文中一共展示了File.readAsArrayBuffer方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1:

	readFileAsArrayBuffer: (directory: string, name: string) =>
		Bluebird.resolve(FILE.readAsArrayBuffer(directory, name)),
開發者ID:whispeer,項目名稱:app,代碼行數:2,代碼來源:blobCache.ts

示例2: fixFileReader

const readFileAsBlob = (path, filename, type) => {
	fixFileReader()
	return FILE.readAsArrayBuffer(path, filename).then((buf) => new Blob([buf], { type }))
}
開發者ID:whispeer,項目名稱:app,代碼行數:4,代碼來源:blobCache.ts

示例3: unzip

    /**
     * Extracts files from a ZIP archive.
     *
     * @param {string} source Path to the source ZIP file.
     * @param {string} destination Destination folder.
     * @param {Function} [onProgress] Optional callback to be called on progress update
     * @return {Promise<number>} Promise that resolves with a number. 0 is success, -1 is error.
     */
    unzip(source: string, destination: string, onProgress?: Function): Promise<number> {

        // Replace all %20 with spaces.
        source = source.replace(/%20/g, ' ');
        destination = destination.replace(/%20/g, ' ');

        const sourceDir = source.substring(0, source.lastIndexOf('/')),
            sourceName = source.substr(source.lastIndexOf('/') + 1),
            zip = new JSZip();

        // Read the file first.
        return this.file.readAsArrayBuffer(sourceDir, sourceName).then((data) => {

            // Now load the file using the JSZip library.
            return zip.loadAsync(data);
        }).then((): any => {

            if (!zip.files || !Object.keys(zip.files).length) {
                // Nothing to extract.
                return 0;
            }

            // First of all, create the directory where the files will be unzipped.
            const destParent = destination.substring(0, source.lastIndexOf('/')),
                destFolderName = destination.substr(source.lastIndexOf('/') + 1);

            return this.file.createDir(destParent, destFolderName, false);
        }).then(() => {

            const promises = [],
                total = Object.keys(zip.files).length;
            let loaded = 0;

            for (const name in zip.files) {
                const file = zip.files[name];
                let promise;

                if (!file.dir) {
                    // It's a file.
                    const fileDir = name.substring(0, name.lastIndexOf('/')),
                        fileName = name.substr(name.lastIndexOf('/') + 1),
                        filePromises = [];
                    let fileData;

                    if (fileDir) {
                        // The file is in a subfolder, create it first.
                        filePromises.push(this.createDir(destination, fileDir));
                    }

                    // Read the file contents as a Blob.
                    filePromises.push(file.async('blob').then((data) => {
                        fileData = data;
                    }));

                    promise = Promise.all(filePromises).then(() => {
                        // File read and parent folder created, now write the file.
                        const parentFolder = this.textUtils.concatenatePaths(destination, fileDir);

                        return this.file.writeFile(parentFolder, fileName, fileData, {replace: true});
                    });
                } else {
                    // It's a folder, create it if it doesn't exist.
                    promise = this.createDir(destination, name);
                }

                promises.push(promise.then(() => {
                    // File unzipped, call the progress.
                    loaded++;
                    onProgress && onProgress({ loaded: loaded, total: total });
                }));
            }

            return Promise.all(promises).then(() => {
                return 0;
            });
        }).catch(() => {
            // Error.
            return -1;
        });
    }
開發者ID:SATS-Seminary,項目名稱:moodlemobile2,代碼行數:88,代碼來源:zip.ts


注:本文中的@ionic-native/file.File.readAsArrayBuffer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。