private void ParseFile() { BeEncode.Dictionary metainfo; BeParser parser = new BeParser(); // Load file try { FileStream fs = new FileStream(fileName, FileMode.Open); byte[] buffer = new byte[fs.Length]; int readBytes = fs.Read(buffer, 0, buffer.Length); if (readBytes == 0) throw new MetainfoFileException("There is no metaInfo information on file (" + fileName + ")"); // We have the buffer full of data, Parse it !!!! metainfo = parser.Parse(buffer); announce = (BeEncode.String)metainfo["announce"]; info = (BeEncode.Dictionary)metainfo["info"]; } catch (NotSupportedException nse) { throw new MetainfoFileException("Can't read from metaInfo file. [" + nse.Message + "]"); } catch (IOException ioe) { throw new MetainfoFileException("Input/Output error. [" + ioe.Message + "]"); } catch (ObjectDisposedException ode) { throw new MetainfoFileException("File already closed. [" + ode.Message + "]"); } }
public Dictionary(byte[] buffer, int pos, int length) { BeParser parser = new BeParser(); try { Dictionary tempDictionary = parser.Parse(buffer); // Copy all the elements to this Dictionary this.elements = (Hashtable)tempDictionary.elements.Clone(); // Free memory tempDictionary = null; } catch (BePaserException bpe) { /// TODO log error throw new DictionaryException("Error parsing the buffer.", bpe); } }
public Dictionary ReadMetainfoFile() { BeParser parser = new BeParser(); Dictionary dict = parser.Parse(@"C:\Proyectos\SharpTorrent\TestUnit\absetup.exe.torrent"); return dict; }