BadScript 2
Loading...
Searching...
No Matches
BadGZipApi.cs
Go to the documentation of this file.
1using System.IO.Compression;
2using System.Text;
3
7
9
10[BadInteropApi("GZip")]
11internal partial class BadGZipApi
12{
18 [BadMethod(description: "Compresses the given string using the GZip Algorithm")]
19 [return: BadReturn("Compressed Array of bytes")]
20 private static BadArray Compress([BadParameter(description: "String to Compress")] string obj)
21 {
22 MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(obj));
23 MemoryStream compressed = new MemoryStream();
24 using GZipStream ds = new GZipStream(compressed, CompressionMode.Compress);
25 ms.CopyTo(ds);
26 ds.Close();
27
28 return new BadArray(compressed.ToArray()
29 .Select(x => (BadObject)new BadNumber(x))
30 .ToList()
31 );
32 }
33
40 [BadMethod(description: "Inflates the given array of bytes using the GZip Algorithm")]
41 [return: BadReturn("Decompressed String")]
43 [BadParameter(description: "Bytes to Decompress")] byte[] obj)
44 {
45 MemoryStream ms = new MemoryStream(obj);
46 MemoryStream decompressed = new MemoryStream();
47 using GZipStream ds = new GZipStream(ms, CompressionMode.Decompress);
48 ds.CopyTo(decompressed);
49 ds.Close();
50
51 return new BadString(Encoding.UTF8.GetString(decompressed.ToArray()));
52 }
53}
static BadObject Decompress(BadExecutionContext ctx, [BadParameter(description:"Bytes to Decompress")] byte[] obj)
GZip Decompress the given array.
Definition BadGZipApi.cs:42
static BadArray Compress([BadParameter(description:"String to Compress")] string obj)
GZip Compress the given string.
Definition BadGZipApi.cs:20
The Execution Context. Every execution of a script needs a context the script is running in....
Implements a Dynamic List/Array for the BadScript Language.
Definition BadArray.cs:17
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
Implements a Native String.
Definition BadString.cs:9
Contains Compression Extensions and APIs for the BadScript2 Runtime.
Contains the Native Runtime Objects.
Definition BadBoolean.cs:6
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains the Runtime Implementation.