<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Reliably Broken &#187; macports</title>
	<atom:link href="http://reliablybroken.com/b/tag/macports/feed/" rel="self" type="application/rss+xml" />
	<link>http://reliablybroken.com/b</link>
	<description>It&#039;s a blog: let&#039;s do funch!</description>
	<lastBuildDate>Thu, 01 Dec 2011 21:27:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>SharpZipLib and Mac OS X</title>
		<link>http://reliablybroken.com/b/2011/11/sharpziplib-and-mac-os-x/</link>
		<comments>http://reliablybroken.com/b/2011/11/sharpziplib-and-mac-os-x/#comments</comments>
		<pubDate>Fri, 18 Nov 2011 22:50:45 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[macports]]></category>
		<category><![CDATA[mono]]></category>
		<category><![CDATA[zip]]></category>

		<guid isPermaLink="false">http://reliablybroken.com/b/?p=699</guid>
		<description><![CDATA[TL;DR When creating zip archives with SharpZipLib disable Zip64 format if you care about Mac compatibility. Extra TL;DR When creating zip archives with SharpZipLib make sure you set the file size, disabling Zip64 is neither here nor there. A project I am working on sources a zip archive from a Web service, extracts the XML [...]]]></description>
			<content:encoded><![CDATA[<p>TL;DR When creating zip archives with SharpZipLib disable Zip64 format if you care about Mac compatibility.</p>

<p>Extra TL;DR <a href="http://reliablybroken.com/b/2011/12/sharpziplib-and-mac-redux/">When creating zip archives with SharpZipLib make sure you set the file size</a>, disabling Zip64 is neither here nor there.</p>

<p>A project I am working on sources a zip archive from a Web service, extracts the XML file from the zip and then does silly amounts of processing of the data in that XML to produce a new XML file which is returned to the user.</p>

<p>But the sourced zip archive cannot be opened using <a href="http://docs.python.org/library/zipfile.html">Python&#8217;s zipfile module</a>, and when saved on a Mac the archive cannot be opened using the built-in Archive Utility.app. If one double-clicks the zip, Archive Utility.app just compresses it again and sticks &#8220;.cpgz&#8221; on the end of the file name.</p>

<p>Fortunately the developer of the Web service is very helpful (the service is written in C# and runs on Windows) and although he didn&#8217;t know why Macs were having problems (the built-in Windows zip tool can handle the archive fine) he showed me the code that creates the zip file.</p>

<p>Turns out they were using <a href="http://www.icsharpcode.net/opensource/sharpziplib/">SharpZipLib, an open-source library for C#</a>. And it turns out SharpZipLib creates archives using <a href="http://en.wikipedia.org/wiki/ZIP_(file_format)#ZIP64">Zip64 format</a> by default.</p>

<p>The fix was to disable Zip64 when creating the archive. Here&#8217;s a trivial command-line program that creates a zip and disables Zip64 for Mac compatibility:</p>

<pre><code>using System;
using System.IO;
using ICSharpCode.SharpZipLib.Core;
using ICSharpCode.SharpZipLib.Zip;


public class ZipTool
{
    public static void Main(string[] args)
    {
        if (args.Length != 2) {
            Console.WriteLine("Usage: ziptool &lt;input file&gt; &lt;output file&gt;");
            return;
        }

        using (ZipOutputStream zipout = new ZipOutputStream(File.Create(args[1]))) {
            byte[] buffer = new byte[4096];
            string filename = args[0];

            zipout.SetLevel(9);

            // Disable Zip64 for Mac compatibility
            zipout.UseZip64 = UseZip64.Off;

            ZipEntry entry = new ZipEntry(Path.GetFileName(filename));            
            entry.DateTime = File.GetLastWriteTime(filename);
            zipout.PutNextEntry(entry);

            using (FileStream fs = File.OpenRead(filename)) {
                int sourceBytes;
                do {
                    sourceBytes = fs.Read(buffer, 0, buffer.Length);
                    zipout.Write(buffer, 0, sourceBytes);
                } while (sourceBytes &gt; 0);
            }

            zipout.Finish();
            zipout.Close();
        }
    }
}
</code></pre>

<p>The disadvantage of disabling Zip64 is you cannot create archives larger than 4 gigabytes, nor can you add files larger than 4 gigabytes before compression.</p>

<p>The advantage of disabling Zip64 is you make me and all my Mac-using hippy friends happy. In concrete terms, disabling Zip64 makes it more likely I will buy you a drink.</p>

<p>Hi Gaston!</p>

<p>Also many thanks to the maintainer of NAnt in <a href="http://www.macports.org/">MacPorts</a>, who responded to <a href="http://trac.macports.org/ticket/32097">my bug report</a> and pushed an updated NAnt to MacPorts extremely quickly. Although SharpZipLib doesn&#8217;t officially support <a href="http://www.mono-project.com/">Mono</a>, it builds without a hitch using the &#8220;build-net-2.0&#8243; target if you hack the <code>SharpZlib.build</code> NAnt script like so:</p>

<pre><code>&lt;target name="build-mono-2.0" &gt;
    &lt;call target="build-net-2.0" /&gt;
    &lt;!--&lt;fail message="Dont know how to build for Mono 2.0." /&gt;--&gt;
&lt;/target&gt;
</code></pre>

<p>Also thanks to the Mono project! Saved me having to fire up a Windows virtual machine to figure out this problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://reliablybroken.com/b/2011/11/sharpziplib-and-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using MacPorts behind a firewall</title>
		<link>http://reliablybroken.com/b/2010/03/using-macports-behind-a-firewall/</link>
		<comments>http://reliablybroken.com/b/2010/03/using-macports-behind-a-firewall/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 11:37:39 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[macports]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://reliablybroken.com/b/?p=420</guid>
		<description><![CDATA[I failed to persuade MySQLdb to build on a Mac OS X Server 10.5.8 install using the system Python + MySQL installation. So I turned to MacPorts where I know I can get Django + all the bits working without much hassle (but with much patience). The next problem was that MacPorts couldn&#8217;t update because [...]]]></description>
			<content:encoded><![CDATA[<p>I failed to persuade <a href="http://mysql-python.sourceforge.net/MySQLdb.html">MySQLdb</a> to build on a <a href="http://www.apple.com/server/macosx/">Mac OS X Server 10.5.8</a> install using the system <a href="http://www.python.org/">Python</a> + <a href="http://www.mysql.com/">MySQL</a> installation. So I turned to <a href="http://www.macports.org/">MacPorts</a> where I know I can get <a href="http://www.djangoproject.com/">Django</a> + all the bits working without much hassle (but with much patience).</p>

<p>The next problem was that MacPorts couldn&#8217;t update because <a href="http://samba.anu.edu.au/rsync/">rsync</a> was blocked by the corporate access policy. Fortunately plain HTTP is permitted outbound. Here&#8217;s how to use a local ports tree.</p>

<p>Install MacPorts using the disk image for 10.5.</p>

<pre><code>curl -O http://distfiles.macports.org/MacPorts/MacPorts-1.8.2-10.5-Leopard.dmg
hdiutil attach MacPorts-1.8.2-10.5-Leopard.dmg
sudo installer -pkg /Volumes/MacPorts-1.8.2/MacPorts-1.8.2.pkg -target /
hdiutil detach /Volumes/MacPorts-1.8.2
</code></pre>

<p>If the MacPorts install directories are not in your $PATH environment, you can add them to your <code>.profile</code>. This change will not take effect until you start a new terminal session.</p>

<pre><code>cat &gt;&gt; ~/.profile &lt;&lt;EOF
PATH=/opt/local/bin:/opt/local/sbin:${PATH}
MANPATH=/opt/local/share/man:${MANPATH}
EOF
</code></pre>

<p>After you have installed MacPorts, create a directory for the ports tree and check it out using <a href="http://subversion.tigris.org/">Subversion</a>.</p>

<pre><code>sudo mkdir -p /opt/local/var/macports/sources/svn.macports.org/trunk/dports
cd /opt/local/var/macports/sources/svn.macports.org/trunk/dports
sudo svn co http://svn.macports.org/repository/macports/trunk/dports/ .
</code></pre>

<p>N.B. In the last line beginning <code>svn co ...</code> the trailing directory separator is significant!</p>

<p>Now tell MacPorts to use the local checkout rather than rsync. Edit <code>/opt/local/etc/macports/sources.conf</code> and add a new line to the end with the path to the ports tree, then comment out the previous line that uses rsync. Here are the last lines from my configuration:</p>

<pre><code>#rsync://rsync.macports.org/release/ports/ [default]
file:///opt/local/var/macports/sources/svn.macports.org/trunk/dports/ [default]
</code></pre>

<p>Finally you must create an index for the tree (otherwise you will see messages saying &#8220;Warning: No index(es) found!&#8221;).</p>

<pre><code>cd /opt/local/var/macports/sources/svn.macports.org/trunk/dports
sudo portindex
</code></pre>

<p>Now go do great things.</p>
]]></content:encoded>
			<wfw:commentRss>http://reliablybroken.com/b/2010/03/using-macports-behind-a-firewall/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

