rv = serv->NewChannelFromURI("load", pURL, nsnull, nsnull,
rv = serv->NewChannelFromURI("load", pURL, nsnull, nsnull, nsnull,
NS_NewURItoFile(const char *in, nsFileSpec dirSpec, const char *out){    nsresult rv;    gKeepRunning = 0;    // Create the Event Queue for this thread...    NS_WITH_SERVICE(nsIEventQueueService, eventQService,                     kEventQueueServiceCID, &rv);    if (NS_FAILED(rv)) return rv;    rv = eventQService->CreateThreadEventQueue();    if (NS_FAILED(rv)) return rv;    rv = eventQService->GetThreadEventQueue(PR_CurrentThread(), &gEventQ);    if (NS_FAILED(rv)) return rv;    NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);    if (NS_FAILED(rv)) return rv;    nsCOMPtr<nsIURI> pURL;    rv = serv->NewURI(in, nsnull, getter_AddRefs(pURL));    if (NS_FAILED(rv)) return rv;    nsCOMPtr<nsIChannel> pChannel;    // Async reading thru the calls of the event sink interface    rv = serv->NewChannelFromURI("load", pURL, nsnull, nsnull,                                  getter_AddRefs(pChannel));    if (NS_FAILED(rv)) {        printf("ERROR: NewChannelFromURI failed for %s\n", in);        return rv;    }                InputConsumer* listener;    listener = new InputConsumer;    NS_IF_ADDREF(listener);    if (!listener) {        NS_ERROR("Failed to create a new stream listener!");        return NS_ERROR_OUT_OF_MEMORY;;    }    rv = listener->Init(dirSpec, out);    if (NS_FAILED(rv)) {        NS_RELEASE(listener);        return rv;    }    rv = pChannel->AsyncRead(0,         // starting position                             -1,        // number of bytes to read                             nsnull,    // ISupports context                             listener); // IStreamListener consumer    if (NS_SUCCEEDED(rv)) {         gKeepRunning = 1;    }    NS_RELEASE(listener);    if (NS_FAILED(rv)) return rv;    // Enter the message pump to allow the URL load to proceed.    while ( gKeepRunning ) {#ifdef WIN32        MSG msg;        if (GetMessage(&msg, NULL, 0, 0)) {            TranslateMessage(&msg);            DispatchMessage(&msg);        } else {            gKeepRunning = 0;        }#else        PLEvent *gEvent;        rv = gEventQ->GetEvent(&gEvent);        if (NS_SUCCEEDED(rv)) {            rv  = gEventQ->HandleEvent(gEvent);        }#endif /* !WIN32 */    }    return rv;}