BadScript 2
Loading...
Searching...
No Matches
BadDeflateApi.cs
Go to the documentation of this file.
1using System.IO.Compression;
2using System.Text;
3
7
9
10[BadInteropApi("Deflate")]
11internal partial class BadDeflateApi
12{
18 [BadMethod(description: "Compresses the given string using the Deflate 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 DeflateStream ds = new DeflateStream(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 Deflate Algorithm")]
38 [return: BadReturn("Decompressed String")]
39 private static string Decompress(BadExecutionContext ctx, [BadParameter(description: "Bytes to Decompress")] byte[] obj)
40 {
41 MemoryStream ms = new MemoryStream(obj);
42 MemoryStream decompressed = new MemoryStream();
43 using DeflateStream ds = new DeflateStream(ms, CompressionMode.Decompress);
44 ds.CopyTo(decompressed);
45 ds.Close();
46
47 return Encoding.UTF8.GetString(decompressed.ToArray());
48 }
49}
static BadArray Compress([BadParameter(description:"String to Compress")] string obj)
Deflates the given string.
static string Decompress(BadExecutionContext ctx, [BadParameter(description:"Bytes to Decompress")] byte[] obj)
Inflate the given array.
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
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.