<?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>tom.higgy &#187; function</title>
	<atom:link href="http://higgy.bandnet.org/tag/function/feed/" rel="self" type="application/rss+xml" />
	<link>http://higgy.bandnet.org</link>
	<description>Moose moose mog mog rat rat</description>
	<lastBuildDate>Mon, 22 Feb 2010 00:00:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>eD2k hash generation in PHP</title>
		<link>http://higgy.bandnet.org/2010/01/ed2k-hash-generation-in-php/</link>
		<comments>http://higgy.bandnet.org/2010/01/ed2k-hash-generation-in-php/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 18:40:06 +0000</pubDate>
		<dc:creator>tom.higgy</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[ed2k]]></category>
		<category><![CDATA[filesharing]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[p2p]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://higgy.bandnet.org/?p=11</guid>
		<description><![CDATA[Spent some time last night fixing a function I wrote ages ago to generate an ed2k hash for a given file. It had a bug.]]></description>
			<content:encoded><![CDATA[<p>Spent some time last night fixing a function I wrote ages ago to generate an ed2k hash for a given file. I then failed to test and fix it with regard to files larger than the chunk size (9,728,000 bytes).</p>
<p>Here&#8217;s an updated version:</p>
<pre>function ed2kHash_file ($name) {
	# Calculates eDonkey2000 hash for any given file
	# By: Tom Higginson
	# Date: 9th January 2008
	# Modified: 11th January 2010
	# License: Public domain

	$chunkSize = 9728000;
	$md4str = '';

	if( !file_exists( $name ) ) {
		return false;
	}

	if( filesize( $name ) < $chunkSize ) {
		return hash_file( 'md4', $name );
	} else {
		$fH = fopen( $name, 'r' );
		while( !feof( $fH ) ) {
			$md4str .= hash( 'md4', fread( $fH, $chunkSize ), true );
		}

		fclose( $fH );

		return hash( 'md4', $md4str );
	}
}</pre>
<p>Here's some more about the eD2k hash: http://en.wikipedia.org/wiki/Ed2k_URI_scheme</p>
]]></content:encoded>
			<wfw:commentRss>http://higgy.bandnet.org/2010/01/ed2k-hash-generation-in-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
