(name, data, o)
| 12872 | * @return {Object} the new file. |
| 12873 | */ |
| 12874 | var fileAdd = function(name, data, o) { |
| 12875 | // be sure sub folders exist |
| 12876 | var dataType = utils.getTypeOf(data), |
| 12877 | parent; |
| 12878 | |
| 12879 | o = prepareFileAttrs(o); |
| 12880 | |
| 12881 | if (typeof o.unixPermissions === "string") { |
| 12882 | o.unixPermissions = parseInt(o.unixPermissions, 8); |
| 12883 | } |
| 12884 | |
| 12885 | // UNX_IFDIR 0040000 see zipinfo.c |
| 12886 | if (o.unixPermissions && (o.unixPermissions & 0x4000)) { |
| 12887 | o.dir = true; |
| 12888 | } |
| 12889 | // Bit 4 Directory |
| 12890 | if (o.dosPermissions && (o.dosPermissions & 0x0010)) { |
| 12891 | o.dir = true; |
| 12892 | } |
| 12893 | |
| 12894 | if (o.dir) { |
| 12895 | name = forceTrailingSlash(name); |
| 12896 | } |
| 12897 | |
| 12898 | if (o.createFolders && (parent = parentFolder(name))) { |
| 12899 | folderAdd.call(this, parent, true); |
| 12900 | } |
| 12901 | |
| 12902 | if (o.dir || data === null || typeof data === "undefined") { |
| 12903 | o.base64 = false; |
| 12904 | o.binary = false; |
| 12905 | data = null; |
| 12906 | dataType = null; |
| 12907 | } |
| 12908 | else if (dataType === "string") { |
| 12909 | if (o.binary && !o.base64) { |
| 12910 | // optimizedBinaryString == true means that the file has already been filtered with a 0xFF mask |
| 12911 | if (o.optimizedBinaryString !== true) { |
| 12912 | // this is a string, not in a base64 format. |
| 12913 | // Be sure that this is a correct "binary string" |
| 12914 | data = utils.string2binary(data); |
| 12915 | } |
| 12916 | } |
| 12917 | } |
| 12918 | else { // arraybuffer, uint8array, ... |
| 12919 | o.base64 = false; |
| 12920 | o.binary = true; |
| 12921 | |
| 12922 | if (!dataType && !(data instanceof CompressedObject)) { |
| 12923 | throw new Error("The data of '" + name + "' is in an unsupported format !"); |
| 12924 | } |
| 12925 | |
| 12926 | // special case : it's way easier to work with Uint8Array than with ArrayBuffer |
| 12927 | if (dataType === "arraybuffer") { |
| 12928 | data = utils.transformTo("uint8array", data); |
| 12929 | } |
| 12930 | } |
| 12931 |
nothing calls this directly
no test coverage detected