Esempio n. 1
0
        internal TarArchiveEntry CreateEntry(string name, Stream data)
        {
            lock (this)
            {
                TarIOEntry entry;
                this.realEntries.Add(entry = new TarIOEntry()
                {
                    Length = BLOCK_SIZE,
                    Offset = baseStream.Length + BLOCK_SIZE,
                    Entry  = new TarArchiveEntry(archive, name, this.realEntries.Count),
                });

                baseStream.Seek(0, SeekOrigin.End);
                baseStream.SetLength(baseStream.Length + BLOCK_SIZE * 2);

                var header = new TarIOFileHeader()
                {
                    Filename     = name,
                    LastModified = DateTime.Now,
                    Size         = data.Length,
                    Type         = LinkIndicator.File
                };
                header.Serialise(baseStream);

                entry.Stream = new TarIOFileItemStream(entry.Offset, entry.Length, baseStream);
                data.CopyTo(entry.Stream);

                return(entry.Entry);
            }
        }
Esempio n. 2
0
        internal Stream OpenStream(int index)
        {
            lock (this)
            {
                if (index < 0 || index >= this.realEntries.Count)
                {
                    throw new ArgumentOutOfRangeException("index");
                }

                TarIOEntry entry = realEntries[index];

                if (entry.Stream != null && entry.Stream.Closed)
                {
                    throw new InvalidOperationException(
                              "A stream for the requested resouce is already open");
                }
                else
                {
                    var @return = new TarIOFileItemStream(entry.Offset, entry.Length, this);
                    realEntries[index].Stream = @return;

                    return(@return);
                }
            }
        }