nsresult nsJARInputThunk::Init() { nsresult rv; if (ENTRY_IS_DIRECTORY(mJarEntry)) { // A directory stream also needs the Spec of the FullJarURI // because is included in the stream data itself. NS_ENSURE_STATE(!mJarDirSpec.IsEmpty()); rv = mJarReader->GetInputStreamWithSpec(mJarDirSpec, mJarEntry, getter_AddRefs(mJarStream)); } else { rv = mJarReader->GetInputStream(mJarEntry, getter_AddRefs(mJarStream)); } if (NS_FAILED(rv)) { // convert to the proper result if the entry wasn't found // so that error pages work if (rv == NS_ERROR_FILE_TARGET_DOES_NOT_EXIST) rv = NS_ERROR_FILE_NOT_FOUND; return rv; } // ask the JarStream for the content length uint64_t avail; rv = mJarStream->Available((uint64_t *) &avail); if (NS_FAILED(rv)) return rv; mContentLength = avail < INT64_MAX ? (int64_t) avail : -1; return NS_OK; }
nsresult nsJARInputThunk::EnsureJarStream() { if (mJarStream) return NS_OK; nsresult rv; if (mJarCache) rv = mJarCache->GetZip(mJarFile, getter_AddRefs(mJarReader)); else { // create an uncached jar reader mJarReader = do_CreateInstance(kZipReaderCID, &rv); if (NS_FAILED(rv)) return rv; rv = mJarReader->Open(mJarFile); } if (NS_FAILED(rv)) return rv; if (ENTRY_IS_DIRECTORY(mJarEntry)) { // A directory stream also needs the Spec of the FullJarURI // because is included in the stream data itself. NS_ENSURE_STATE(!mJarDirSpec.IsEmpty()); rv = mJarReader->GetInputStreamWithSpec(mJarDirSpec, mJarEntry.get(), getter_AddRefs(mJarStream)); } else { rv = mJarReader->GetInputStream(mJarEntry.get(), getter_AddRefs(mJarStream)); } if (NS_FAILED(rv)) { // convert to the proper result if the entry wasn't found // so that error pages work if (rv == NS_ERROR_FILE_TARGET_DOES_NOT_EXIST) rv = NS_ERROR_FILE_NOT_FOUND; return rv; } // ask the JarStream for the content length // XXX want a 64-bit value from nsIInputStream::Available() PRUint32 contentLength; rv = mJarStream->Available(&contentLength); if (NS_FAILED(rv)) return rv; mContentLength = contentLength; return NS_OK; }