Ejemplo n.º 1
0
 public void HeaderHasLengthOfItemStart()
 {
     var ms = new MemoryStream();
     var desc = new TeaFileDescription();
     desc.ContentDescription = "a";
     var wc = HeaderManager.Instance.WriteHeader(new FormattedWriter(new FileIO(ms)), desc);
     ms.Length.Should().Be(wc.ItemAreaStart);
     ms.Position.Should().Be(wc.ItemAreaStart);
     (ms.Position % 8).Should().Be(0);
 }
        public void HeaderHasLengthOfItemStart()
        {
            var ms   = new MemoryStream();
            var desc = new TeaFileDescription();

            desc.ContentDescription = "a";
            var wc = HeaderManager.Instance.WriteHeader(new FormattedWriter(new FileIO(ms)), desc);

            ms.Length.Should().Be(wc.ItemAreaStart);
            ms.Position.Should().Be(wc.ItemAreaStart);
            (ms.Position % 8).Should().Be(0);
        }
Ejemplo n.º 3
0
 public void HeaderWithContentDescription()
 {
     var ms = new MemoryStream();
     var desc = new TeaFileDescription();
     desc.ContentDescription = "a";
     var wc = HeaderManager.Instance.WriteHeader(new FormattedWriter(new FileIO(ms)), desc);
     ms.Length.Should().Be.GreaterThan(4 * 8);
     ms.Position.Should().Be(wc.ItemAreaStart);
     (ms.Position % 8).Should().Be(0);
     ms.Position = 0;
     var rc = HeaderManager.Instance.ReadHeader(new FormattedReader(new FileIO(ms)));
     rc.Should().Not.Be.Null();
     rc.ItemAreaStart.Should().Be.GreaterThan(32);
     rc.ItemAreaEnd.Should().Be(0);
     rc.SectionCount.Should().Be(1);
     ms.Position.Should().Be(ms.Length);
     ms.Position.Should().Be(rc.ItemAreaStart);
     (ms.Position % 8).Should().Be(0);
 }
Ejemplo n.º 4
0
        public WriteContext WriteHeader(IFormattedWriter w, TeaFileDescription description)
        {
            var wc = new WriteContext(w);
            wc.ItemAreaStart = 32; //  if no sections are created, ItemArea will start at 32. This value will change is sections are created

            wc.Description = description;
            byte[] sections = this.CreateSections(wc);

            w.WriteInt64(0x0d0e0a0402080500);
            w.WriteInt64(wc.ItemAreaStart);
            w.WriteInt64(0);
            w.WriteInt64(wc.SectionCount);
            wc.Writer.WriteRaw(sections);

            //var sectionPadding = wc.ItemAreaStart - w.Position;
            //if (sectionPadding < 0) throw new FileFormatException("Stream position (potentially after writing sections) is behind item start. After opening a TeaFile and reading the header, the file pointer must be exactly at the begin of the item area.");
            //w.WriteZeroBytes((int) sectionPadding);

            return wc;
        }
        public WriteContext WriteHeader(IFormattedWriter w, TeaFileDescription description)
        {
            var wc = new WriteContext(w);

            wc.ItemAreaStart = 32; //  if no sections are created, ItemArea will start at 32. This value will change is sections are created

            wc.Description = description;
            byte[] sections = this.CreateSections(wc);

            w.WriteInt64(0x0d0e0a0402080500);
            w.WriteInt64(wc.ItemAreaStart);
            w.WriteInt64(0);
            w.WriteInt64(wc.SectionCount);
            wc.Writer.WriteRaw(sections);

            //var sectionPadding = wc.ItemAreaStart - w.Position;
            //if (sectionPadding < 0) throw new FileFormatException("Stream position (potentially after writing sections) is behind item start. After opening a TeaFile and reading the header, the file pointer must be exactly at the begin of the item area.");
            //w.WriteZeroBytes((int) sectionPadding);

            return(wc);
        }
        public void HeaderWithContentDescription()
        {
            var ms   = new MemoryStream();
            var desc = new TeaFileDescription();

            desc.ContentDescription = "a";
            var wc = HeaderManager.Instance.WriteHeader(new FormattedWriter(new FileIO(ms)), desc);

            ms.Length.Should().Be.GreaterThan(4 * 8);
            ms.Position.Should().Be(wc.ItemAreaStart);
            (ms.Position % 8).Should().Be(0);
            ms.Position = 0;
            var rc = HeaderManager.Instance.ReadHeader(new FormattedReader(new FileIO(ms)));

            rc.Should().Not.Be.Null();
            rc.ItemAreaStart.Should().Be.GreaterThan(32);
            rc.ItemAreaEnd.Should().Be(0);
            rc.SectionCount.Should().Be(1);
            ms.Position.Should().Be(ms.Length);
            ms.Position.Should().Be(rc.ItemAreaStart);
            (ms.Position % 8).Should().Be(0);
        }