Table of Contents

Class BundleWriter

Namespace
OpaDotNet.Compilation.Abstractions
Assembly
OpaDotNet.Compilation.Abstractions.dll

Implements writing files into OPA policy bundle.

public sealed class BundleWriter : IDisposable, IAsyncDisposable
Inheritance
BundleWriter
Implements
Inherited Members

Examples

using var ms = new MemoryStream();

using (var writer = new BundleWriter(ms))
{
    writer.WriteEntry("package test", "policy.rego");
}

// Now bundle have been constructed.
ms.Seek(0, SeekOrigin.Begin);
...

Remarks

You need to dispose BundleWriter instance before you can use resulting bundle.

Constructors

BundleWriter(Stream, BundleManifest?)

Creates new instance of BundleWriter.

public BundleWriter(Stream stream, BundleManifest? manifest = null)

Parameters

stream Stream

Stream to write bundle to.

manifest BundleManifest

Policy bundle manifest.

Properties

IsEmpty

true if BundleWriter has no entries written; otherwise false.

public bool IsEmpty { get; }

Property Value

bool

Methods

Dispose()

public void Dispose()

DisposeAsync()

public ValueTask DisposeAsync()

Returns

ValueTask

FromDirectory(Stream, string, IReadOnlySet<string>?)

Creates new instance of BundleWriter and populates it with files in path.

public static BundleWriter FromDirectory(Stream stream, string path, IReadOnlySet<string>? exclusions)

Parameters

stream Stream

Stream to write bundle to.

path string

Path containing bundle source files.

exclusions IReadOnlySet<string>

File name patterns for files the BundleWriter should exclude from the results.

Returns

BundleWriter

MergeCapabilities(Stream, Stream)

Merges two capabilities.json streams.

public static Stream MergeCapabilities(Stream caps1, Stream caps2)

Parameters

caps1 Stream

First capabilities.json stream.

caps2 Stream

Second capabilities.json stream.

Returns

Stream

New merged capabilities.json stream.

WriteBundle(Stream)

Merges contents of source bundle into this bundle.

public void WriteBundle(Stream bundle)

Parameters

bundle Stream

Source bundle.

WriteBundle(Span<byte>)

Merges contents of source bundle into this bundle.

public void WriteBundle(Span<byte> bundle)

Parameters

bundle Span<byte>

Source bundle.

WriteEntry(Stream, string)

Writes stream content into bundle.

public void WriteEntry(Stream stream, string path)

Parameters

stream Stream

String content.

path string

Relative file path inside bundle.

WriteEntry(ReadOnlySpan<byte>, string)

Writes bytes content into bundle.

public void WriteEntry(ReadOnlySpan<byte> bytes, string path)

Parameters

bytes ReadOnlySpan<byte>

String content.

path string

Relative file path inside bundle.

WriteEntry(ReadOnlySpan<char>, string)

Writes string content into bundle.

public void WriteEntry(ReadOnlySpan<char> str, string path)

Parameters

str ReadOnlySpan<char>

String content.

path string

Relative file path inside bundle.

WriteFile(string, string?)

Writes contents of file into bundle.

public void WriteFile(string path, string? overridePath = null)

Parameters

path string

File to write.

overridePath string

Relative file path inside bundle.

WriteManifest(BundleManifest)

Writes manifest into bundle.

public void WriteManifest(BundleManifest manifest)

Parameters

manifest BundleManifest

Policy bundle manifest.