(name, data, originalOptions)
| 20 | * @return {Object} the new file. |
| 21 | */ |
| 22 | var fileAdd = function(name, data, originalOptions) { |
| 23 | // be sure sub folders exist |
| 24 | var dataType = utils.getTypeOf(data), |
| 25 | parent; |
| 26 | |
| 27 | |
| 28 | /* |
| 29 | * Correct options. |
| 30 | */ |
| 31 | |
| 32 | var o = utils.extend(originalOptions || {}, defaults); |
| 33 | o.date = o.date || new Date(); |
| 34 | if (o.compression !== null) { |
| 35 | o.compression = o.compression.toUpperCase(); |
| 36 | } |
| 37 | |
| 38 | if (typeof o.unixPermissions === "string") { |
| 39 | o.unixPermissions = parseInt(o.unixPermissions, 8); |
| 40 | } |
| 41 | |
| 42 | // UNX_IFDIR 0040000 see zipinfo.c |
| 43 | if (o.unixPermissions && (o.unixPermissions & 0x4000)) { |
| 44 | o.dir = true; |
| 45 | } |
| 46 | // Bit 4 Directory |
| 47 | if (o.dosPermissions && (o.dosPermissions & 0x0010)) { |
| 48 | o.dir = true; |
| 49 | } |
| 50 | |
| 51 | if (o.dir) { |
| 52 | name = forceTrailingSlash(name); |
| 53 | } |
| 54 | if (o.createFolders && (parent = parentFolder(name))) { |
| 55 | folderAdd.call(this, parent, true); |
| 56 | } |
| 57 | |
| 58 | var isUnicodeString = dataType === "string" && o.binary === false && o.base64 === false; |
| 59 | if (!originalOptions || typeof originalOptions.binary === "undefined") { |
| 60 | o.binary = !isUnicodeString; |
| 61 | } |
| 62 | |
| 63 | |
| 64 | var isCompressedEmpty = (data instanceof CompressedObject) && data.uncompressedSize === 0; |
| 65 | |
| 66 | if (isCompressedEmpty || o.dir || !data || data.length === 0) { |
| 67 | o.base64 = false; |
| 68 | o.binary = true; |
| 69 | data = ""; |
| 70 | o.compression = "STORE"; |
| 71 | dataType = "string"; |
| 72 | } |
| 73 | |
| 74 | /* |
| 75 | * Convert content to fit. |
| 76 | */ |
| 77 | |
| 78 | var zipObjectContent = null; |
| 79 | if (data instanceof CompressedObject || data instanceof GenericWorker) { |
nothing calls this directly
no test coverage detected