Power-Fx
Power-Fx copied to clipboard
FileInfo functions
Add 2 new functions that work with files (https://github.com/microsoft/Power-Fx/blob/main/src/libraries/Microsoft.PowerFx.Core/Public/Values/BlobValue.cs)
These don't need to be included by default yet. But can be pulled in via:
Config.EnableFileFunctions()
FileInfo
New function, called "FileInfo", which takes a blob and returns a record of file information:
FileInfo(Blob): FileInfo
Where:
FileInfo = Type(
{
Name: Text,
Size: Decimal, // 53 bits is large enough
MIMEType: Text,
URL: Text
});
Blob is a File type in Power Fx (Dtype.Blob) Note: Power Fx only has Floating point /Decimal numberic types (no integer types).
Text(Blob) // should return appres URL, not impl in C# interpreter yet.
// semantically same as: FileInfo(Blob).URL
PatchFileInfo
PatchFileInfo( File: Blob, UpdatedInfo: FileInfo ): Blob
For changing the file name, it would be PatchFileInfo( MyFile, { Name: "My new file name" } ).
Won't allow updating Size/Url. Runtime error. So this would be an error: PatchFileInfo(Blob, FileInfo(blob))
Open Issues:
- Size is Number of Decimal?
- Final name of PatchFileInfo
Implementation plan
- In C# side, we define new virtuals on BlobValue for GetFileInfo, SetFileInfo.
- Power Fx side defines the two functions above
- Their impl will call the new virtuals on BlobValue
Hosts are already derive from BlobValue, and so you would just implement those virtuals as you see fit.
It sounds like there wer esome offline conversations:
- Remove Patch/Update function. Just readonly
- Remove URL property on FileInfo.
- Keep Opt-in. (config.EnableFileFunctions)