BadScript 2
Loading...
Searching...
No Matches
BadZLibApi.cs
Go to the documentation of this file.
1using System.IO.Compression;
2using System.Text;
3
7
9
10[BadInteropApi("ZLib")]
11internal partial class BadZLibApi
12{
18 [BadMethod(description: "Compresses the given string using the ZLib Algorithm")]
19 [return: BadReturn("Compressed Array of bytes")]
20 private static BadObject 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 ZLibStream ds = new ZLibStream(compressed, CompressionMode.Compress);
25 ms.CopyTo(ds);
26 ds.Close();
27
28 return new BadArray(compressed.ToArray().Select(x => (BadObject)new BadNumber(x)).ToList());
29 }
30
37 [BadMethod(description: "Inflates the given array of bytes using the ZLib Algorithm")]
38 [return: BadReturn("Decompressed String")]
39 private static BadObject Decompress(BadExecutionContext ctx, [BadParameter(description: "Bytes to Decompress")] byte[] obj)
40 {
41 MemoryStream ms = new MemoryStream(obj);
42 MemoryStream decompressed = new MemoryStream();
43 using ZLibStream ds = new ZLibStream(ms, CompressionMode.Decompress);
44 ds.CopyTo(decompressed);
45 ds.Close();
46
47 return new BadString(Encoding.UTF8.GetString(decompressed.ToArray()));
48 }
49}
static BadObject Compress([BadParameter(description:"String to Compress")] string obj)
ZLib Compress the given string.
Definition BadZLibApi.cs:20
static BadObject Decompress(BadExecutionContext ctx, [BadParameter(description:"Bytes to Decompress")] byte[] obj)
ZLib Decompress the given array.
Definition BadZLibApi.cs:39
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.