Binary.View
BinaryCreates a custom view of a binary value with handler functions that override default operation behavior.
Syntax
Binary.View(binary as nullable binary, handlers as record) as binaryParameters
| Name | Type | Required | Description |
|---|---|---|---|
binary | binary | No | The base binary value to create a view of. If null, the GetStream handler is required. |
handlers | record | Yes | A record of handler functions that replace the default behavior of operations applied to the view. |
Return Value
binary — A binary view where specified handler functions override default operation behavior.
Remarks
Binary.View creates a custom binary view where handler functions override the default behavior of operations applied to the binary. This is the binary-stream equivalent of Table.View and is primarily used in custom connector development to implement folding for binary data sources.
When an operation is applied to the view:
1. If a matching handler exists, it is called. 2. If the handler raises an error, the engine falls back to applying the operation against the base binary. Use Binary.ViewError to raise errors that bypass this fallback. 3. If no handler exists, the default behavior is applied to binary.
If binary is null, the GetStream handler is required since there is no base binary to fall back to.
Common handler functions include:
GetStream— returns the binary stream content. Called when the binary data is accessed.GetLength— returns the length of the binary without reading the full stream.GetExpression— returns the M expression representing the view.OnInvoke— called when a view function (created viaBinary.ViewFunction) is invoked on the view.
Refer to the published Power Query custom connector documentation for a complete description of Binary.View.
Examples
Example 1: Create a basic view with a custom length handler
let
View = Binary.View(
null,
[
GetLength = () => 12,
GetStream = () => Text.ToBinary("hello world!")
]
),
Len = Binary.Length(View)
in
LenCalls Binary.Length on the view, which invokes the GetLength handler and returns 12 without reading the stream.
Value | |
|---|---|
| 1 | 12 |