Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try
- {
- writeln("Downloading: " ~ filename ~ " ...");
- auto sock = new TcpSocket(new InternetAddress(domain, 80));
- auto ss = new SocketStream(sock);
- scope(exit) sock.close(); // close the socket when quit the program
- ss.writeString("GET " ~ url ~ " HTTP/1.0\r\n"
- "Host: " ~ domain ~ "\r\n"
- "\r\n");
- // Skip Http header and fill the string who contain the original catalog
- while (true)
- {
- auto line = ss.readLine();
- if (!line.length) break;
- }
- ubyte[4096] buffer; // buffer size: 4kb
- while (!ss.eof())
- {
- int read = ss.readBlock(&buffer, buffer.length);
- content ~= buffer[0..read];
- }
- writeln("Download finish: " ~ filename);
- }
- catch(Exception e)
- {
- writeln("fatal error in downloader thread (" ~ filename ~ "):\r\n" ~ e.toString());
- return;
- }
Add Comment
Please, Sign In to add comment