FromStream() public method

public FromStream ( Stream stream ) : void
stream Stream
return void
Ejemplo n.º 1
0
        public static ArchiveFileLib FromStream(Stream stream)
        {
            ArchiveFileLib file = new ArchiveFileLib();

            byte[] buffer = new byte[Windows.Constants.IMAGE_ARCHIVE_START_SIZE];
            stream.Read(buffer, 0, Windows.Constants.IMAGE_ARCHIVE_START_SIZE);

            bool valid = Encoding.ASCII.GetString(buffer) == Windows.Constants.IMAGE_ARCHIVE_START;
            if (!valid) throw new InvalidDataException("Not a valid archive file");

            file.first.FromStream(stream);
            file.second.FromStream(stream);
            file.longnames.FromStream(stream);

            List<ObjectFileMember> objects = new List<ObjectFileMember>();

            while (stream.CanRead && (stream.Position < stream.Length))
            {
                try
                {
                    var ofm = new ObjectFileMember();
                    ofm.FromStream(stream);
                    objects.Add(ofm);
                }
                catch
                {
                    file.Errors = true;
                    break;
                }
            }

            file.objects = objects.ToArray();

            return file;
        }