Example #1
0
            public static ArchiveInputStream Create(System.IO.Stream stream, ArchiveType type)
            {
                switch (type)
                {
                case ArchiveType.zip:
                    return(ArchiveInputStream.CreateZipStream(stream));

                case ArchiveType.tgz:
                    return(ArchiveInputStream.CreateTgzStream(stream));

                default:
                    throw new ArgumentException();
                }
            }
Example #2
0
        public static void Extract(ArchiveInputStream stream, string outDir, Parte p, long totalData)
        {
            ArchiveEntry entrada = null;
            byte[] buffer = new byte[Consts.BUFFER_LENGTH];
            int leidos = 0;
            if (p != null) {
                p.OnProgress (0, 1);
            }
            while ((entrada = stream.GetNextEntry ()) != null) 	{

                if (entrada.IsDirectory) {
                    continue;
                }
                if (entrada.IsLink){
                    // TODO Implementar el link.
                    continue;

                }
                leidos = 0;
                try {
                    Stream s = Dalle.Utilidades.UtilidadesFicheros.CreateWriter (outDir + Path.DirectorySeparatorChar + entrada.Name);
                    while ((leidos = stream.Read (buffer)) > 0)	{
                        s.Write (buffer, 0, leidos);

                        if (leidos > 0 && p != null) {
                            if (totalData > 0) {
                                p.OnProgress (stream.Position, totalData);
                            } else if (stream.Length > 0) {
                                p.OnProgress (stream.Position, stream.Length);
                            }
                        }

                    }
                    s.Close ();
                }
                catch (Exception ex) {
                    Console.WriteLine(ex.StackTrace);
                }
            }
            if (p != null) {
                if (totalData > 0) {
                    p.OnProgress (stream.Position, totalData);
                } else if (stream.Length > 0) {
                    p.OnProgress (stream.Position, stream.Length);
                } else {
                    p.OnProgress (1, 1);
                }
            }
            stream.Close ();
        }
Example #3
0
        private void Extract(System.IO.Stream stream, string filename, Project project = null, Directory directory = null)
        {
            using (var archiveInputStream = ArchiveInputStream.Create(stream, ArchiveTypeHelpers.GetType(filename)))
            {
                while (archiveInputStream.GetNextEntry() is ArchiveEntry archiveEntry)
                {
                    var file = this.EnsureCreated(project, directory, archiveEntry.Name, archiveEntry.IsFile);

                    if (file != null && archiveEntry.IsFile)
                    {
                        var buffer = new byte[4096];

                        using (var contentStream = new System.IO.MemoryStream())
                        {
                            StreamUtils.Copy(archiveInputStream.Stream, contentStream, buffer);
                            file.Content = Encoding.ASCII.GetString(contentStream.ToArray());
                        }
                    }
                }
            }
        }
        private void Init()
        {
            ReadRPMLead ();
            ReadRPMSignature ();
            ReadRPMHeader ();
            if (this.payloadSize > 0)
            {
                this.totalLength = this.Position + this.payloadSize;
            }

            long limitSize = this.inputStream.Length - this.inputStream.Position;
            Stream s = new SizeLimiterStream(this.inputStream,limitSize);
            switch (payloadCompressor)
            {
                case "gzip":
                    s = new GZipStream(s, CompressionMode.Decompress);
                    break;
                case "bzip2":
                    s = new BZip2InputStream (s);
                    break;
                case "lzma":
                    s = new LZMAInputStream(s);
                    break;
                default:
                    throw new IOException("Unsupported payload compression:" + payloadCompressor);
            }
            switch (payloadFormat){
                case "cpio":
                    cpioStream = new CpioArchiveInputStream(s);
                    break;
                default :
                    throw new IOException("Unsupported payload format:" + payloadFormat);
            }
        }
Example #5
0
 public static void Extract(ArchiveInputStream stream, string outDir, Parte p)
 {
     Extract (stream, outDir, p, -1);
 }
Example #6
0
        /**
         * Performs all changes collected in this ChangeSet on the input stream and
         * streams the result to the output stream. Perform may be called more than once.
         *
         * This method finishes the stream, no other entries should be added
         * after that.
         *
         * @param in
         *            the InputStream to perform the changes on
         * @param out
         *            the resulting OutputStream with all modifications
         * @throws IOException
         *             if an read/write error occurs
         * @return the results of this operation
         */
        public ChangeSetResults perform(ArchiveInputStream inJ, ArchiveOutputStream outJ)
        //throws IOException
        {
            ChangeSetResults results = new ChangeSetResults();

            java.util.Set <Change> workingSet = new java.util.LinkedHashSet <Change>(changes);

            for (java.util.Iterator <Change> it = workingSet.iterator(); it.hasNext();)
            {
                Change change = it.next();

                if (change.type() == Change.TYPE_ADD && change.isReplaceMode())
                {
                    copyStream(change.getInput(), outJ, change.getEntry());
                    it.remove();
                    results.addedFromChangeSet(change.getEntry().getName());
                }
            }

            ArchiveEntry entry = null;

            while ((entry = inJ.getNextEntry()) != null)
            {
                bool copy = true;

                for (java.util.Iterator <Change> it = workingSet.iterator(); it.hasNext();)
                {
                    Change change = it.next();

                    int    type = change.type();
                    String name = entry.getName();
                    if (type == Change.TYPE_DELETE && name != null)
                    {
                        if (name.equals(change.targetFile()))
                        {
                            copy = false;
                            it.remove();
                            results.deleted(name);
                            break;
                        }
                    }
                    else if (type == Change.TYPE_DELETE_DIR && name != null)
                    {
                        if (name.StartsWith(change.targetFile() + "/"))
                        {
                            copy = false;
                            results.deleted(name);
                            break;
                        }
                    }
                }

                if (copy)
                {
                    if (!isDeletedLater(workingSet, entry) && !results.hasBeenAdded(entry.getName()))
                    {
                        copyStream(inJ, outJ, entry);
                        results.addedFromStream(entry.getName());
                    }
                }
            }

            // Adds files which hasn't been added from the original and do not have replace mode on
            for (java.util.Iterator <Change> it = workingSet.iterator(); it.hasNext();)
            {
                Change change = it.next();

                if (change.type() == Change.TYPE_ADD &&
                    !change.isReplaceMode() &&
                    !results.hasBeenAdded(change.getEntry().getName()))
                {
                    copyStream(change.getInput(), outJ, change.getEntry());
                    it.remove();
                    results.addedFromChangeSet(change.getEntry().getName());
                }
            }
            outJ.finish();
            return(results);
        }