Skip to main content

NewBytesReadCloser

Creates a new io.ReadCloser from a byte slice. The returned io.ReadCloser wraps a bytes.Reader initialized with the provided byte slice.

def NewBytesReadCloser(
b: []byte
) - > io.ReadCloser

Creates a new io.ReadCloser from a byte slice. This function is useful for treating an in-memory byte array as a readable and closable stream, allowing it to be used with APIs that expect an io.ReadCloser.

Parameters

NameTypeDescription
b[]byteThe byte slice to be wrapped as an io.ReadCloser. The returned reader will read directly from this slice.

Returns

TypeDescription
io.ReadCloserA new io.ReadCloser instance that reads from the provided byte slice.