例如,我想创建一个大小为10mb的文件,因此为此我使用了cordova-plugin-file和Blob,但它只适用于小尺寸,因为Blob
have own limitations
那么,我如何创建1gb,2gb,3gb的文件......?
我的示例代码(此作品小尺寸[< 7mb]):
export interface FileInfo {
size : number,
path : string,
filename : string,
fullpath:string
}
let random : string = 'tmp-' + (Math.random().toString(36).substring(7).toString());
let tmpFile : FileInfo = {
size : 10000000, // 10mb
path : cordova.file.dataDirectory,
filename: random,
fullpath: (cordova.file.dataDirectory + '/' + random).replace(/\/+/g, '/')
};
let blob:Blob = new Blob(<any>(new Uint8Array(tmpFile.size)), {
type:'text/plain; charset=utf-8'
});
this.file.resolveLocalFilesystemUrl(tmpFile.path).then((directory:DirectoryEntry) => {
directory.getFile(tmpFile.filename, {
create:true
}, (file:FileEntry) => {
file.createWriter((writer:FileWriter) => {
writer.seek(writer.length);
writer.write(blob);
file.file((info:any) => {
console.log(tmpFile)
}, (err:FileError) => {
console.error(err)
})
}, (err:FileError) => {
console.error(err)
})
}, (err:FileError) => {
console.error(err)
})
}, (err:any) => {
console.error(err)
});
P.S:我正在使用Ionic 3和TypeScript(显然)。
谢谢!