Binary.View

The binary view function allows for the customization of operation behavior by specifying handler functions. These handlers are used instead of the default behavior when an operation is applied to the...

Syntax

Binary.View(binary as nullable binary, handlers as record) as binary

About

The binary view function allows for the customization of operation behavior by specifying handler functions. These handlers are used instead of the default behavior when an operation is applied to the binary view. When providing binary input, all handler functions are optional. However, when binary is not provided, the GetStream handler function becomes mandatory. If a specific handler function is not defined for an operation, the default behavior of that operation is executed on the binary view, except for GetExpression. Handler functions are required to return a result that is equivalent in meaning to the outcome of applying the operation on the binary input (or the resulting view in the case of GetExpression). In case of an error raised by a handler function, the default operation behavior is implemented on the view. Binary.View is utilized for implementing folding to a data source, which involves translating M queries into source-specific operations, such as downloading a portion of a file.

Explanation

Generate a simplistic view that can determine the length without the need to access the data. The code snippet below accomplishes this by defining the view using Power Query M language: Power Query M code: ``` Binary.View( null, [ GetLength = () => 12, GetStream = () => Text.ToBinary("hello world!") ] ) ``` The resulting output will be the binary representation of the text "hello world!" in Power Query M language: ``` Text.ToBinary("hello world!") ```