bool QtNPStream::finish(QtNPBindable *bindable)
{
    if (!bindable)
        return false;

    bool res = false;
    if (bindable) {
        switch(reason) {
        case NPRES_DONE:
            // no data at all? url is probably local file (Opera)
            if (buffer.isEmpty() && file.fileName().isEmpty()) {
                QUrl u = QUrl::fromEncoded(stream->url);
                QString lfn = u.toLocalFile();
                if (lfn.startsWith("//localhost/"))
                    lfn = lfn.mid(12);
                file.setFileName(lfn);
            }

            if (file.exists()) {
                file.setObjectName(url());
                res = bindable->readData(&file, mime);
            } else {
                QBuffer io(&buffer);
                io.setObjectName(url());
                res = bindable->readData(&io, mime);
            }
            break;
        case NPRES_USER_BREAK:
            {
                ErrorBuffer empty;
                empty.setObjectName(url());
                empty.setErrorString("User cancelled operation."),
                res = bindable->readData(&empty, mime);
            }
            break;
        case NPRES_NETWORK_ERR:
            {
                ErrorBuffer empty;
                empty.setObjectName(url());
                empty.setErrorString("Network error during download."),
                res = bindable->readData(&empty, mime);
            }
            break;
        default:
            break;
        }
    }
    stream->pdata = 0;
    delete this;
    return res;
}