daily pastebin goal
44%
SHARE
TWEET

Untitled

a guest Nov 30th, 2018 111 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         try
  2.         {
  3.             writeln("Downloading: " ~ filename ~ " ...");
  4.             auto sock = new TcpSocket(new InternetAddress(domain, 80));
  5.             auto ss = new SocketStream(sock);
  6.             scope(exit) sock.close(); // close the socket when quit the program
  7.             ss.writeString("GET " ~ url ~ " HTTP/1.0\r\n"
  8.                            "Host: " ~ domain ~ "\r\n"
  9.                            "\r\n");
  10.             // Skip Http header and fill the string who contain the original catalog
  11.             while (true)
  12.             {
  13.                 auto line = ss.readLine();
  14.                 if (!line.length) break;
  15.             }
  16.  
  17.             ubyte[4096] buffer; // buffer size: 4kb
  18.             while (!ss.eof())
  19.             {
  20.                 int read = ss.readBlock(&buffer, buffer.length);
  21.                 content ~=  buffer[0..read];
  22.             }
  23.             writeln("Download finish: " ~ filename);
  24.         }
  25.         catch(Exception e)
  26.         {
  27.             writeln("fatal error in downloader thread (" ~ filename ~ "):\r\n" ~ e.toString());
  28.             return;
  29.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top