1 // =================================
 2 // Copyright (c) 2022 Seppo Laakko
 3 // Distributed under the MIT license
 4 // =================================
 5 
 6 using System.Os;
 7 
 8 namespace System
 9 {
10     public DecompressedDataPtr Decompress(byte* bufferlong count)
11     {
12         return DecompressedDataPtr(System.Os.Decompress(buffercount));
13     }
14     
15     public class DecompressedDataPtr
16     {
17         public DecompressedDataPtr(int dd_) : dd(dd_)size(GetDecompressedDataSize(dd))
18         {
19             data = cast<byte*>(MemAlloc(size));
20             GetDecompressedData(dddatasize);
21         }
22         suppress DecompressedDataPtr(const DecompressedDataPtr&);
23         suppress void operator=(const DecompressedDataPtr&);
24         public nothrow DecompressedDataPtr(DecompressedDataPtr&& that) : dd(that.dd)data(that.data)size(that.size)
25         {
26             that.dd = -1;
27             that.data = null;
28             that.size = -1;
29         }
30         public default nothrow void operator=(DecompressedDataPtr&& that);
31         public ~DecompressedDataPtr()
32         {
33             if (data != null)
34             {
35                 MemFree(data);
36             }
37             if (dd != -1)
38             {
39                 close_decompression(dd);
40             }
41         }
42         public nothrow int Descriptor() const
43         {
44             return dd;
45         }
46         public nothrow byte* Data() const
47         {
48             return data;
49         }
50         public nothrow long Size() const
51         {
52             return size;
53         }
54         public nothrow byte* ReleaseData()
55         {
56             byte* result = data;
57             data = null;
58             return result;
59         }
60         private int dd;
61         private byte* data;
62         private long size;
63     }
64 }