Power-Fx icon indicating copy to clipboard operation
Power-Fx copied to clipboard

FileInfo functions

Open MikeStall opened this issue 10 months ago • 1 comments

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:

  1. Size is Number of Decimal?
  2. Final name of PatchFileInfo

Implementation plan

  1. In C# side, we define new virtuals on BlobValue for GetFileInfo, SetFileInfo.
  2. Power Fx side defines the two functions above
  3. 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.

MikeStall avatar Apr 24 '24 15:04 MikeStall

It sounds like there wer esome offline conversations:

  1. Remove Patch/Update function. Just readonly
  2. Remove URL property on FileInfo.
  3. Keep Opt-in. (config.EnableFileFunctions)

MikeStall avatar May 03 '24 00:05 MikeStall