MCPcopy Create free account
hub / github.com/hoothin/UserScripts / fileAdd

Function fileAdd

Picviewer CE+/Picviewer CE+.user.js:1619–1698  ·  view source on GitHub ↗
(name, data, originalOptions)

Source from the content-addressed store, hash-verified

1617 * @return {Object} the new file.
1618 */
1619var fileAdd = function(name, data, originalOptions) {
1620 // be sure sub folders exist
1621 var dataType = utils.getTypeOf(data),
1622 parent;
1623
1624
1625 /*
1626 * Correct options.
1627 */
1628
1629 var o = utils.extend(originalOptions || {}, defaults);
1630 o.date = o.date || new Date();
1631 if (o.compression !== null) {
1632 o.compression = o.compression.toUpperCase();
1633 }
1634
1635 if (typeof o.unixPermissions === "string") {
1636 o.unixPermissions = parseInt(o.unixPermissions, 8);
1637 }
1638
1639 // UNX_IFDIR 0040000 see zipinfo.c
1640 if (o.unixPermissions && (o.unixPermissions & 0x4000)) {
1641 o.dir = true;
1642 }
1643 // Bit 4 Directory
1644 if (o.dosPermissions && (o.dosPermissions & 0x0010)) {
1645 o.dir = true;
1646 }
1647
1648 if (o.dir) {
1649 name = forceTrailingSlash(name);
1650 }
1651 if (o.createFolders && (parent = parentFolder(name))) {
1652 folderAdd.call(this, parent, true);
1653 }
1654
1655 var isUnicodeString = dataType === "string" && o.binary === false && o.base64 === false;
1656 if (!originalOptions || typeof originalOptions.binary === "undefined") {
1657 o.binary = !isUnicodeString;
1658 }
1659
1660
1661 var isCompressedEmpty = (data instanceof CompressedObject) && data.uncompressedSize === 0;
1662
1663 if (isCompressedEmpty || o.dir || !data || data.length === 0) {
1664 o.base64 = false;
1665 o.binary = true;
1666 data = "";
1667 o.compression = "STORE";
1668 dataType = "string";
1669 }
1670
1671 /*
1672 * Convert content to fit.
1673 */
1674
1675 var zipObjectContent = null;
1676 if (data instanceof CompressedObject || data instanceof GenericWorker) {

Callers

nothing calls this directly

Calls 2

forceTrailingSlashFunction · 0.70
parentFolderFunction · 0.70

Tested by

no test coverage detected