magic.lambda.io
17.2.0
dotnet add package magic.lambda.io --version 17.2.0
NuGet\Install-Package magic.lambda.io -Version 17.2.0
<PackageReference Include="magic.lambda.io" Version="17.2.0" />
paket add magic.lambda.io --version 17.2.0
#r "nuget: magic.lambda.io, 17.2.0"
// Install magic.lambda.io as a Cake Addin #addin nuget:?package=magic.lambda.io&version=17.2.0 // Install magic.lambda.io as a Cake Tool #tool nuget:?package=magic.lambda.io&version=17.2.0
magic.lambda.io - Accessing your file system from Hyperlambda
This project provides file/folder slots for Magic. More specifically, it provides the following slots.
- [io.folder.create] - Creates a folder on disc for you on your server
- [io.folder.exists] - Returns true if folder exists, otherwise false
- [io.folder.delete] - Deletes a folder on disc on your server
- [io.folder.list] - Lists all folders within another source folder
- [io.folder.move] - Moves a folder to its specified destination
- [io.folder.copy] - Copies a folder to its specified destination
- [io.file.load] - Loads a file from disc on your server
- [load-file] - Alias for [io.file.load]
- [io.file.load.binary] - Loads a file from disc on your server as a byte array
- [io.file.save] - Saves a file on disc on your server
- [save-file] - Alias for [io.file.save]
- [io.file.save.binary] - Saves a file on disc on your server but contrary to the above assumes content to save is binary
- [io.file.exists] - Returns true if file exists, otherwise false.
- [io.file.delete] - Deletes a file on your server.
- [io.file.copy] - Copies a file on your server.
- [io.file.execute] - Executes a Hyperlambda file on your server.
- [execute-file] - Alias for [io.file.execute] except it will forward evaluate all descendant nodes using [unwrap]
- [io.file.list] - List files in the specified folder on your server.
- [io.file.move] - Moves a file on your server.
- [io.file.unzip] - Unzips a file on your server.
- [io.stream.open-file] - Opens the specified filename and returns it as a stream
- [io.stream.save-file] - Saves a stream to the specified destination path
- [io.stream.read] - Reads all content from the specified stream as a byte array
- [io.stream.close] - Closes a previously opened stream
- [io.content.zip-stream] - Creates a ZipStream for you, without touching the file system
- [.io.folder.root] - Returns the root folder of your system. (private C# slot)
- [io.file.mixin] - Allows you to invoke lambda objects from a file and substitute content dynamically in your original file
magic.lambda.io fundamentals
magic.lambda.io can only manipulate files and folders inside of your "files" folder in your web server. This are normally files inside of the folder you have configured in your "appsettings.json" file, with the key "magic.io.root-folder". This implies that all paths are relative to this path, and no files or folders from outside of this folder can in any ways be manipulated using these slots. These are the files you can see when you open Hyper IDE.
Notice, if you wish to change this configuration value, then the character tilde "~" means root folder where your application is running from within. There is nothing preventing you from using an absolute path, but if you do, you must make sure your web server process have full rights to modify files within this folder. We do not recommend changing this configuration setting.
How to use [io.folder.create]
Creates a new folder on disc. The example below will create a folder named "foo" inside of the "misc" folder. Notice, will throw an exception if the folder already exists.
io.folder.create:/misc/foo/
How to use [io.folder.exists]
Returns true if specified folder exists on disc.
io.folder.exists:/misc/foo/
How to use [io.folder.delete]
Deletes the specified folder on disc. Notice, will throw an exception if the folder doesn't exists.
io.folder.delete:/misc/foo/
How to use [io.folder.list]
Lists all folders inside of the specified folder. By default hidden folders will not be shown, unless you pass in [display-hidden] and set its value to boolean "true".
io.folder.list:/misc/
How to use [io.folder.move]
Moves the specified source folder to its specified destination folder.
io.folder.move:/misc/source-folder/
.:/misc/destination-folder/
How to use [io.folder.copy]
Copies the specified source folder to its specified destination folder. Notice, this slot doesn't copy the folder itself, but rather the folder's content. Below is an example.
io.folder.copy:/misc/source-folder/
.:/misc/destination-folder/
After invocation of the above, every single file and folder inside your "source-folder" can now be found as a copy inside your "destination-folder".
How to use [io.file.load]
Loads the specified text file from disc. This slot can only load text files. Or to be specific, there are no ways you can change binary files, hence loading a binary file is for the most parts not something you should do. Although there might exist exceptions to this.
io.file.load:/misc/README.md
Notice - If you want to load binary content you should use the [io.file.load.binary] override.
How to use [io.file.save]
Saves the specified content to the specified file on disc, overwriting any previous content if the file exists from before, creating a new file if no such file already exists. The value of the first argument will be considered the content of the file.
Notice, the node itself will be evaluated, allowing you to have other slots evaluated before slot saves the file, to return dynamically the content of your file.
io.file.save:/misc/README2.md
.:This is new content for file
Notice - If you want to save binary content you should use the [io.file.save.binary] override.
How to use [io.file.exists]
Returns true if specified file exists from before.
io.file.exists:/misc/README.md
How to use [io.file.delete]
Deletes the specified file. Will throw an exception if the file doesn't exist.
io.file.load:/misc/DOES-NOT-EXIST.md
How to use [io.file.copy]
Copies the specified file to the specified destination folder and file. Notice, requires the destination folder to exist from before, and the source file to exist from before. This slot will delete any previously existing destination file, before starting the copying process. Just like the save slot, this will evaluate the lambda children before it executes the copying of your file, allowing you to use the results of slots as the destination path for your file.
io.file.copy:/misc/README.md
.:/misc/backup/README-backup.md
Notice, the folder parts of thye destination folder is optional, and if you don't supply a folder as a part of the path, the source folder will be used by default.
How to use [io.file.execute]
Executes the specified Hyperlambda file. Just like when evaluating a dynamic slot, you can pass in an [.arguments] node to the file, which will be considered arguments to your file. Hence, this slot allows you to invoke a file, as if it was a dynamically created slot, and there is no semantic difference really between this slot and [signal] from the magic.lambda.slots project.
io.file.execute:/misc/some-hyperlambda-file.hl
How to use [execute-file]
The [execute-file] slot is an alias for [io.file.execute], but it will [unwrap] all children nodes, automatically transform any expressions to their static value equivalents, allowing you to combine [unwrap] and [io.file.execute] into one invocation. This makes usage slightly less verbose for cases such as the following.
.args
foo1:bar1
foo2:bar2
execute-file:/whatever-file.hl
arg1:x:@.args/*/foo1
arg2:x:@.args/*/foo2
In the above example both arguments to our "/whatever-file.hl" file will be evaluated before the file is executed, resulting in [arg1] and [args2] having the values of "bar1" and "bar2" respectively.
If you pass in a node named [node_reference] using the above syntax, this node will be especially handled, and passed in by reference instead of evaluated as a single expression value. Consider the following alternative to the above.
.args
foo1:bar1
foo2:bar2
execute-file:/whatever-file.hl
node_reference:x:@.args
Inside your above "/whatever-file.hl" file you will now have access to the entire [.args] node by reference.
How to use [io.file.list]
Lists all files inside of the specified folder. By default hidden files will not be shown, unless you pass in [display-hidden] and set its value to boolean "true".
io.file.list:/misc/
How to use [io.file.move]
Similar to [io.file.copy] but deletes the source file after evaluating.
io.file.move:/misc/README.md
.:/misc/backup/README-backup.md
How to use [io.file.unzip]
Unzips a ZIP file. Notice, the [folder] argument is optional, and the current folder of the ZIP file you're unzipping will be used if no [folder] argument is given.
io.file.unzip:/misc/foo.zip
folder:/misc/backup/
How to use [io.file.mixin]
This slot takes a filename as its primary argument, and optionally any amount of lambda children objects.
It allows for dynamically substituting for instance {{ '{{' }}*/.name}}
segments in your original source file,
by invoking lambda objects it can find by evaluating your {{ '{{' }}xyz}}
segment as an expression
leading to some lambda object you want to execute. Below is an example of usage that assumes you've got a
file named "foo.html" at the root folder of your installation resembling the following.
/foo.html
<html>
<head>
<title>Hello world</title>
</head>
<body>
<h1>Hello world</h1>
<p>
Hello there {{ '{{' }}*/.name}}, 2 + 5 is {{ '{{' }}*/.add}}
</p>
</body>
</html>
If you create the above file you can invoke [io.file.mixin] as follows to see the result.
io.file.mixin:/foo.html
.name:Thomas Hansen
.add
math.add
.:int:2
.:int:5
return:x:-
The above will substitute all your {{xyz}}
segments and give you a result resembling the following.
<html>
<head>
<title>Hell world</title>
</head>
<body>
<h1>Hello world</h1>
<p>
Hello there Thomas Hansen, 2 + 5 is 7
</p>
</body>
</html>
Notice, if the node your expression is leading to has a value such as illustrated above, it will return that value instead of executing your node as a lambda object.
All [.oninit] lambda objects found as children of your [io.file.mixin] invocation will be executed before any mixin logic is executed, allowing for you to create common initialisation logic, that runs once but is referenced in multiple mixin expressions.
How to use [io.content.zip-stream]
Creates a memory based ZIP stream you can return over the HTTP response object. Notice, this doesn't create a zip file, but rather a zip stream, which you can manipulate using other slots. This slot is useful if you need to return zipped content as your HTTP response for instance.
Notice, both the root arguments (lambda children) of this slot will be evaluated, in addition to its content nodes, evaluated once for each file declaration node. Notice also that the stream is a memory bases stream, and hence closing it, even in case of an exception, is not necessary.
io.content.zip-stream
.:/foo/x.txt
.:content of file
How to use [io.stream.open-file]
Works similarly to [io.file.load] but instead of returning the file's content, it returns the raw stream back to caller.
io.stream.open-file:/foo/bar.txt
After invoking the above, assuming the file exists, a raw Stream
object can be
found as the value of the [io.stream.open-file] node.
How to use [io.stream.save-file]
Works similarly to [io.file.save] but instead of taking source content of some kind,
it assumes the source is an open Stream
of some sort.
/*
* [.stream] here is an open stream, from for instance the HTTP
* request object, or something similar that somehow is able to open
* a stream and pass around in Hyperlambda.
*/
.stream
io.stream.save-file:/foo/bar.txt
get-value:x:@.stream
After invoking the above, assuming the [.stream] node contains a valid Stream
object, the file above will contain the content from the stream.
Notice - If the file exists from before the existing file will be deleted, unless you pass in an [overwrite] argument and set its value to false, at which point an exception will be thrown if the file exists from before.
How to use [io.stream.read]
Works similarly to [io.file.load] but instead of taking a source filename of some kind,
it assumes the source is an open Stream
of some sort.
/*
* [.stream] here is an open stream, from for instance the HTTP
* request object, or something similar.
*/
.stream
io.stream.read:x:@.stream
How to use [io.stream.close]
Closes a previously opened stream.
Notice - You would rarely directly use streams from Hyperlambda, and not manipulate them in any ways, but rather use for instance [io.file.load] and similar "high level" slots - And only use streams when you need to directly access the HTTP request stream, to persist a file uploaded by a user, or return a file over the HTTP response object. Hence, directly opening a stream for any other purpose but to return it over the HTTP response object is something you'd probably never want to do. And if you return the stream over the HTTP response object, .Net takes ownership over the stream, and ensures it is closed and disposed. However, for completeness we've still provided the ability to explicitly close a stream using the [io.stream.close] - Even though you would probably never really need to use it. Besides, opening streams for any other purpose but to return them over the HTTP response object, might also create leaks, since there is no means to guarantee that the stream is close in case of exceptions, etc - Unless you explicitly take care of such things manually.
io.stream.open-file:/foo/bar.txt
io.stream.close:x:-
After invoking the above, assuming [.stream] is a valid stream, the stream's raw
byte[]
content can be found in [io.stream.read].
How to use [.io.folder.root]
Returns the root folder of the system. Cannot be invoked from Hyperlambda, but only from C#. Intended as a support function for other C# slots.
var node = new Node();
signaler.Signal(".io.folder.root", node);
// Retrieving root folder after evaluating slot.
var rootFolder = node.Get<string>();
Magic's GitHub project page
Magic is 100% Open Source and you can find the primary project GitHub page here.
Project website for magic.lambda.io
The source code for this repository can be found at github.com/polterguy/magic.lambda.io, and you can provide feedback, provide bug reports, etc at the same place.
Copyright and maintenance
The projects is copyright Thomas Hansen 2023 - 2024, and professionally maintained by AINIRO.IO.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- magic.node.extensions (>= 17.2.0)
- magic.signals.contracts (>= 17.2.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on magic.lambda.io:
Package | Downloads |
---|---|
magic.library
Helper project for Magic to wire up everything easily by simply adding one package, and invoking two simple methods. When using Magic, this is (probably) the only package you should actually add, since this package pulls in everything else you'll need automatically, and wires up everything sanely by default. To use package go to https://polterguy.github.io |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
17.2.0 | 438 | 1/22/2024 |
17.1.7 | 184 | 1/12/2024 |
17.1.6 | 168 | 1/11/2024 |
17.1.5 | 169 | 1/5/2024 |
17.0.1 | 220 | 1/1/2024 |
17.0.0 | 377 | 12/14/2023 |
16.11.5 | 354 | 11/12/2023 |
16.9.0 | 346 | 10/9/2023 |
16.7.0 | 591 | 7/11/2023 |
16.4.1 | 409 | 7/2/2023 |
16.4.0 | 430 | 6/22/2023 |
16.3.1 | 384 | 6/7/2023 |
16.3.0 | 377 | 5/28/2023 |
16.1.9 | 648 | 4/30/2023 |
15.10.11 | 507 | 4/13/2023 |
15.9.1 | 653 | 3/27/2023 |
15.9.0 | 494 | 3/24/2023 |
15.8.2 | 538 | 3/20/2023 |
15.7.0 | 392 | 3/6/2023 |
15.5.0 | 1,608 | 1/28/2023 |
15.2.0 | 682 | 1/18/2023 |
15.1.0 | 1,177 | 12/28/2022 |
14.5.7 | 756 | 12/13/2022 |
14.5.5 | 834 | 12/6/2022 |
14.5.1 | 704 | 11/23/2022 |
14.5.0 | 663 | 11/18/2022 |
14.4.5 | 751 | 10/22/2022 |
14.4.1 | 778 | 10/22/2022 |
14.4.0 | 701 | 10/17/2022 |
14.3.1 | 1,275 | 9/12/2022 |
14.3.0 | 686 | 9/10/2022 |
14.1.3 | 956 | 8/7/2022 |
14.1.2 | 693 | 8/7/2022 |
14.1.1 | 720 | 8/7/2022 |
14.0.14 | 741 | 7/26/2022 |
14.0.12 | 692 | 7/24/2022 |
14.0.11 | 698 | 7/23/2022 |
14.0.10 | 671 | 7/23/2022 |
14.0.9 | 675 | 7/23/2022 |
14.0.8 | 746 | 7/17/2022 |
14.0.5 | 840 | 7/11/2022 |
14.0.4 | 777 | 7/6/2022 |
14.0.3 | 749 | 7/2/2022 |
14.0.2 | 698 | 7/2/2022 |
14.0.0 | 875 | 6/25/2022 |
13.4.0 | 2,087 | 5/31/2022 |
13.3.4 | 1,475 | 5/9/2022 |
13.3.0 | 968 | 5/1/2022 |
13.2.2 | 788 | 4/25/2022 |
13.2.0 | 929 | 4/21/2022 |
13.1.0 | 1,046 | 4/7/2022 |
13.0.0 | 766 | 4/5/2022 |
11.0.7 | 1,145 | 3/10/2022 |
11.0.5 | 848 | 3/2/2022 |
11.0.4 | 819 | 2/22/2022 |
11.0.3 | 789 | 2/9/2022 |
11.0.2 | 856 | 2/6/2022 |
11.0.1 | 826 | 2/5/2022 |
10.0.21 | 808 | 1/28/2022 |
10.0.20 | 777 | 1/27/2022 |
10.0.19 | 803 | 1/23/2022 |
10.0.18 | 772 | 1/17/2022 |
10.0.15 | 979 | 12/31/2021 |
10.0.14 | 588 | 12/28/2021 |
10.0.13 | 638 | 12/23/2021 |
10.0.11 | 542 | 12/23/2021 |
10.0.9 | 553 | 12/22/2021 |
10.0.8 | 584 | 12/22/2021 |
10.0.7 | 752 | 12/22/2021 |
10.0.5 | 785 | 12/18/2021 |
9.9.9 | 1,743 | 11/29/2021 |
9.9.4 | 1,102 | 11/21/2021 |
9.9.3 | 570 | 11/9/2021 |
9.9.2 | 684 | 11/4/2021 |
9.9.0 | 777 | 10/30/2021 |
9.8.9 | 747 | 10/29/2021 |
9.8.7 | 689 | 10/27/2021 |
9.8.6 | 658 | 10/27/2021 |
9.8.5 | 756 | 10/26/2021 |
9.8.0 | 1,426 | 10/20/2021 |
9.7.9 | 663 | 10/19/2021 |
9.7.5 | 1,509 | 10/14/2021 |
9.7.0 | 894 | 10/9/2021 |
9.6.6 | 1,247 | 8/14/2021 |
9.6.2 | 1,288 | 8/9/2021 |
9.5.8 | 1,439 | 8/4/2021 |
9.4.5 | 1,373 | 6/29/2021 |
9.3.6 | 1,212 | 6/21/2021 |
9.2.0 | 2,841 | 5/26/2021 |
9.1.4 | 1,309 | 4/21/2021 |
9.1.0 | 1,077 | 4/14/2021 |
9.0.0 | 888 | 4/5/2021 |
8.9.9 | 505 | 3/30/2021 |
8.9.4 | 1,555 | 3/26/2021 |
8.9.3 | 1,024 | 3/19/2021 |
8.9.2 | 1,041 | 1/29/2021 |
8.9.1 | 1,052 | 1/24/2021 |
8.9.0 | 1,116 | 1/22/2021 |
8.6.9 | 3,034 | 11/8/2020 |
8.6.6 | 2,016 | 11/2/2020 |
8.6.0 | 4,000 | 10/28/2020 |
8.5.0 | 1,898 | 10/23/2020 |
8.4.0 | 5,609 | 10/13/2020 |
8.3.1 | 2,685 | 10/5/2020 |
8.3.0 | 1,287 | 10/3/2020 |
8.2.2 | 2,082 | 9/26/2020 |
8.2.1 | 1,365 | 9/25/2020 |
8.2.0 | 1,373 | 9/25/2020 |
8.1.19 | 3,262 | 9/21/2020 |
8.1.18 | 2,697 | 9/13/2020 |
8.1.17 | 1,967 | 9/13/2020 |
8.1.16 | 657 | 9/13/2020 |
8.1.15 | 1,917 | 9/12/2020 |
8.1.11 | 2,497 | 9/11/2020 |
8.1.10 | 1,315 | 9/6/2020 |
8.1.9 | 1,341 | 9/3/2020 |
8.1.8 | 1,328 | 9/2/2020 |
8.1.7 | 1,235 | 8/28/2020 |
8.1.4 | 1,249 | 8/25/2020 |
8.1.3 | 1,306 | 8/18/2020 |
8.1.2 | 1,237 | 8/16/2020 |
8.1.1 | 1,283 | 8/15/2020 |
8.1.0 | 606 | 8/15/2020 |
8.0.2 | 1,986 | 8/7/2020 |
8.0.1 | 1,309 | 8/7/2020 |
8.0.0 | 1,247 | 8/7/2020 |
7.0.1 | 1,370 | 6/28/2020 |
7.0.0 | 1,288 | 6/28/2020 |
5.0.1 | 3,374 | 5/29/2020 |
5.0.0 | 4,687 | 2/25/2020 |
4.0.4 | 7,868 | 1/27/2020 |
4.0.3 | 1,305 | 1/27/2020 |
4.0.2 | 1,431 | 1/16/2020 |
4.0.1 | 1,415 | 1/11/2020 |
4.0.0 | 1,414 | 1/5/2020 |
3.1.2 | 3,509 | 12/5/2019 |
3.1.1 | 1,406 | 12/4/2019 |
3.1.0 | 2,763 | 11/10/2019 |
3.0.0 | 3,867 | 10/23/2019 |
2.0.1 | 8,285 | 10/15/2019 |
2.0.0 | 1,660 | 10/13/2019 |
1.1.9 | 1,403 | 10/11/2019 |
1.1.8 | 1,327 | 10/10/2019 |
1.1.7 | 613 | 10/9/2019 |
1.1.6 | 650 | 10/7/2019 |
1.1.5 | 650 | 10/6/2019 |
1.1.4 | 652 | 10/6/2019 |
1.1.2 | 638 | 10/5/2019 |
1.0.0 | 705 | 9/26/2019 |