Thread View: news.software.nntp
1 messages
1 total messages
Started by Extremest Extremest
Mon, 11 Feb 2008 21:18
Yenc Help in C#
Author: Extremest Extremest
Date: Mon, 11 Feb 2008 21:18
Date: Mon, 11 Feb 2008 21:18
140 lines
6369 bytes
6369 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();
}
}
}
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads