示例#1
0
        public byte[] ReadFile(string file)
        {
            IntPtr buf  = IntPtr.Zero;
            var    size = InteropMethods.ArchiveReadFile(_instance, file, ref buf);

            if (size == -1)
            {
                // TODO should we use this exception type?
                throw new FileNotFoundException();
            }

            var data = new byte[size];

            Marshal.Copy(buf, data, 0, size);

            InteropMethods.Cleanup(buf);
            return(data);
        }
示例#2
0
        public IReadOnlyList <ArchiveFile> GetFiles()
        {
            int num   = 0;
            var ptr   = InteropMethods.ArchiveGetFiles(_instance, ref num);
            var files = new ArchiveFile[num];

            var size = Marshal.SizeOf(typeof(ArchiveFile));

            for (int i = 0; i < num; i++)
            {
                files[i] = Marshal.PtrToStructure <ArchiveFile>(IntPtr.Add(ptr, i * size));
            }

            // free memory allocated by interop
            InteropMethods.Cleanup(ptr);

            return(files.ToList());
        }