Umm... Are you aware that binary attachments on usenet aren't actually *in* binary? They're encoded in ASCII using one of a number of different methods. They're just text, until decoded on the receiving end.
I recommend looking into File::Slurp and CHI. CHI basically implements the entire caching back-end for you. Sent from my iPhone On 2012-08-11, at 5:21 AM, Chris Knipe <sav...@savage.za.org> wrote: > Hi All, > > I'm using Net::NNTP to transfer articles from servers. My aim is to write > an NNTP proxy. > > I obtain the article from my parent news server, write the file to disk, and > serve the current, as well as future requests for that article from the > local file on the disk. My results are very inconsistent, and I suspect > that it is related to the \r\n line breaks conflicting with the binary data > retrieved from the article (a line may include \r\n when it's not actually > meant to indicate the END of a line). I am currently using: > > local $/ = "\r\n"; > my $Article = $nntp->article($Command['1']); > if ($Article) { > # The parent has the article! Let's take it. > open FILE, ">:raw", $File or die $!; > binmode(FILE); > foreach my $line (@$Article) { > print FILE $line; > } > close(FILE); > $ReturnStr = "220 0 " . $Command['1'] . "\r\n"; > open FILE, "<:raw", $File; > binmode(FILE); > foreach my $line (<FILE>) { > $ReturnStr .= $line; > } > close(FILE); > $ReturnStr .= ".\r\n"; > binmode(STDOUT); > print $ReturnStr; > > For some articles, the above code is absolutely fine and no problems are > returned. For others, the binary attachments to the article (regardless of > type of file), is corrupt, and cannot be opened. The results are also very > inconsistent, and being binary I'm not exactly sure how to provide samples > of what works and what doesn't. I've analysed packet captures excessively, > and I am definitely getting all the data correctly, and consistently from my > parent news server - the problem is related to me writing the file to the > local disk, and serving the content of that file from the local disk. > > Hopefully someone can assist and point me towards the right direction - > after spending close to a week on this, I'm ready to pull out my hair! :-( > -- > Chris. > > > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/