1
Vote

Length not available for the current entry

description

For some zip files i got error "Length not available for the current entry".
 
Stack:
 
at ICSharpCode.SharpZipLib.Zip.ZipInputStream.get_Length()
at EPubReader.Extensions.IsolatedStorageFileExtensions.WriteStream(IsolatedStorageFile isf, String path, Stream stream)
at EPubReader.Utilities.ZipHelper.Extract(Stream stream)
at EPubReader.EPubViewer.OnSourcePropertyChanged(Stream newValue)
at EPubReader.EPubViewer.OnSourcePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet)
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value)
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
at EPubReader.EPubViewer.set_Source(Stream value)
at EPubReader.Test.MainPage..ctor()
at System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo rtci, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
at System.Activator.InternalCreateInstance(Type type, Boolean nonPublic, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type)
at System.Windows.Navigation.PageResourceContentLoader.BeginLoad_OnUIThread(AsyncCallback userCallback, PageResourceContentLoaderAsyncResult result)
at System.Windows.Navigation.PageResourceContentLoader.<>c__DisplayClass4.<BeginLoad>b__0(Object args)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at System.Delegate.DynamicInvokeOne(Object[] args)
at System.MulticastDelegate.DynamicInvokeImpl(Object[] args)
at System.Delegate.DynamicInvoke(Object[] args)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority)
at System.Windows.Threading.Dispatcher.OnInvoke(Object context)
at System.Windows.Hosting.CallbackCookie.Invoke(Object[] args)
at System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object[] args)
at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult)
 
 
I can't include zip file for example; but I can send it to you directly.
 
regards
Jakub Florczyk
jakub.florczyk@gmail.com

comments

ljubomir wrote Jun 10, 2013 at 2:15 PM

Hi Jakub,

i am encountering the same issue. Were you able to find a solution to it?

Thanks & Regards,
Ljubomir

kubaf wrote Jun 23, 2013 at 8:29 AM

I don't remember how I manage to resolve that problem. But below I include part of code which unpack ZIP stream and it works, so maybe that gonna help you.
internal static class ZipHelper
{
    /// <summary>
    /// Extracts the specified stream.
    /// </summary>
    /// <param name="stream">Stream containings EPub file.</param>
    /// <returns>List of extracted files.</returns>
    internal static Collection<string> Extract(Stream stream)
    {
        Collection<string> files = new Collection<string>();

        // purge storage directory
        IsolatedStorageHelper.ClearStorageZipDirectory();

        // enumarate entries
        using (ZipFile file = new ZipFile(stream))
        {
            foreach (ZipEntry entry in file)
            {
                using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    // create directory
                    isf.CreateDirectory(Path.Combine(Globals.StorageZipDirectory, Path.GetDirectoryName(entry.Name)));

                    // save entry stream
                    if (entry.IsFile)
                    {
                        using (Stream entryStrem = file.GetInputStream(entry))
                        {
                            using (IsolatedStorageFileStream isfs = isf.CreateFile(Path.Combine(Globals.StorageZipDirectory, entry.Name)))
                            {
                                entryStrem.CopyTo(isfs);

                                isfs.Close();
                            }

                            entryStrem.Close();
                        }

                        files.Add(entry.Name);
                    }
                }
            }
            file.Close();
        }

        return files;
    }
}

ljubomir wrote Jun 24, 2013 at 7:27 AM

Thanks for the follow up.

After further investigation, i found out that this is a specific issue with SharpZipLib and it relates to the different position of the file size information (after the actual file) which cannot be read properly.

I solved my problem by simply not using SharpZipLib at all. Silverlight seem to have build in support for managing zip formats. I found out realy small and handy helper class SharpGis.UnZipper and had my app working in no time.

For future reference - here is the link to the unzip helper: http://www.sharpgis.net/post/2009/04/22/REALLY-small-unzip-utility-for-Silverlight.aspx

kubaf wrote Jun 24, 2013 at 8:34 AM

Thx for info.

regards
Jakub Florczyk