当前位置: 首页>>代码示例>>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;未经允许,请勿转载。