Article View: news.software.readers
Article #216770Yenc help in C#
From: Extremest Extremest
Date: Mon, 11 Feb 2008 21:18
Date: Mon, 11 Feb 2008 21:18
141 lines
6381 bytes
6381 bytes
I am trying to decode a yenc encoded jpg. I get an image
now, but it is a bunch of colors.
Ok here is my function that goes through the data. I have
gotten it
really close just don't know if there is some encoding on a
stream
that I am doing wrong or what. Code is rough. Want to get
it
working then will clean it up.
static void collect()
{
for (int x = 0; x < msg_ids.Count; x++)
{
Connect();
byte[] buff = new byte[BUFFERSIZE];//buffer
for decoded data.
NetworkStream networkStream =
tcpClient.GetStream();//nntp connection.
StreamReader reader = new StreamReader
(networkStream, Encoding.Default);//reader for nntp
connection.
StreamWriter writer = new StreamWriter
(networkStream);//writer for nntp connection.
writer.AutoFlush = true;
int bufferLength = 0;//where we are in the
buff array.
int filelength = 0;//Length of the file
from the header.
string id = msg_ids[x] as string;//The
msg_id for the article.
string line;//Line that is read from the
connection.
string fileName;//Name of the file from the
header.
id = "body " + id;//build article request.
id = id.Trim();
writer.WriteLine(id);//write article
request to nntp
line = reader.ReadLine();//read response
from nntp
/*Loop until it finds the beginning of the
yenc data*/
while (reader.Peek() >= 0 && line != null
&& !line.StartsWith("=ybegin") &&
!line.StartsWith("begin 644"))
{
line = reader.ReadLine();
if (line == ".")
{
break;
}
}
if (line.StartsWith("begin 644"))//Not
implemented yet.
{
Disconnect();
continue;
}
else
{
if (line == null || line == ".")
{
Disconnect();
continue;
}
fileName = parseForName(line);//get
filename from the header.
string tempsize = parseForString(line,
"size");//get size from the header.
Console.WriteLine(tempsize);
filelength = int.Parse(tempsize);
if (fileName == null)//not valid
header.
{
Disconnect();
continue;
}
String partNo = parseForString(line,
"part");// get part # from header.
if (partNo != null)//check and see if
there are more parts or to remove the line from the code.
{
while (line != null && !
line.StartsWith("=ypart"))
{
line = reader.ReadLine();
Console.WriteLine("--{0}--",
line);
}
if (line == null)
throw new IOException("Error
while handling a multipart reader. Could not locate line
starting with \"=ypart\".");
}
// Decode the file
line = reader.ReadLine();//read first
line of encoded data.
while (line != null && !line.StartsWith
("=yend"))//will go to end of encoded data.
{
for (int lcv = 0; lcv <
line.Length; lcv++)//go through line by char.
{
if (line[lcv] == '=')//find
escape char.
{
lcv++;
buff[bufferLength] =
(byte) ((line[lcv] - 64) - 42);
bufferLength++;
}
else
{
buff[bufferLength] =
(byte) (line[lcv] - 42);
bufferLength++;
}
}
line = reader.ReadLine();//read
next line for the loop.
}
}
if (bufferLength > 0)//check to see if we
decoded anything if so then write it to a file.
{
FileStream fs = File.Create(fileName);
BinaryWriter bw = new BinaryWriter
(fs,Encoding.Default);
bw.Write(buff,0,filelength);
bw.Close();
fs.Close();
}
}
}
Technical Details
Message-ID:
<K7-dnWjy290nJi3anZ2dnUVZ_uHinZ2d@giganews.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local02.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mailShow Full Headers
Complete Article Headers
Message-ID: <K7-dnWjy290nJi3anZ2dnUVZ_uHinZ2d@giganews.com> Subject: Yenc help in C# Date: Mon, 11 Feb 2008 15:18:50 -0600 From: Extremest (Extremest@extremest.com) Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local02.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 11 Feb 2008 15:18:50 -0600 Newsgroups: news.software.readers X-Newsreader: NewsLeecher v3.8 Final (http://www.newsleecher.com) Lines: 141 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-tTASOtrPly9780EP/kouT6D1hg+c+4auNBYVVx8N2E2j4djpx4aeXDWmXgNYMX9AZqe80kWrQPPpqjE!gJXEHJ7BWWILKVIzFYO0XhtmItNECobqViyFM8806loQFOVd+Oyfh5KR8MLYe4YTlHFLVSJ/HP+B X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.37