-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnszipfilereader.ios.js
More file actions
28 lines (25 loc) · 923 Bytes
/
nszipfilereader.ios.js
File metadata and controls
28 lines (25 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const FILE_NOT_FOUND = "File not found withing zip archive";
class NSZipFileReader{
constructor(pPath){
let error = null;
this.zipFile = ZZArchive.archiveWithURLError(NSURL.fileURLWithPath(pPath), error);
}
readString(pFile){
let ref = this;
return new Promise(function(pResolve, pReject){
for(let k = 0; k < ref.zipFile.entries.count; k++){
let e = ref.zipFile.entries.objectAtIndex(k);
if(e.fileName === pFile){
let error = null;
let data = NSString.alloc().initWithDataEncoding(e.newDataWithError(error), NSUTF8StringEncoding);
pResolve(data.toString());
break;
}
}
if (data === undefined) {
pReject(FILE_NOT_FOUND);
}
});
}
}
exports.NSZipFileReader = NSZipFileReader;