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
streamStreamStream to write bundle to.
manifestBundleManifestPolicy bundle manifest.
Properties
IsEmpty
true if BundleWriter has no entries written; otherwise false.
public bool IsEmpty { get; }
Property Value
Methods
Dispose()
public void Dispose()
DisposeAsync()
public ValueTask DisposeAsync()
Returns
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
streamStreamStream to write bundle to.
pathstringPath containing bundle source files.
exclusionsIReadOnlySet<string>File name patterns for files the BundleWriter should exclude from the results.
Returns
MergeCapabilities(Stream, Stream)
Merges two capabilities.json streams.
public static Stream MergeCapabilities(Stream caps1, Stream caps2)
Parameters
Returns
- Stream
New merged capabilities.json stream.
WriteBundle(Stream)
Merges contents of source bundle into this bundle.
public void WriteBundle(Stream bundle)
Parameters
bundleStreamSource bundle.
WriteBundle(Span<byte>)
Merges contents of source bundle into this bundle.
public void WriteBundle(Span<byte> bundle)
Parameters
WriteEntry(Stream, string)
Writes stream content into bundle.
public void WriteEntry(Stream stream, string path)
Parameters
WriteEntry(ReadOnlySpan<byte>, string)
Writes bytes content into bundle.
public void WriteEntry(ReadOnlySpan<byte> bytes, string path)
Parameters
bytesReadOnlySpan<byte>String content.
pathstringRelative file path inside bundle.
WriteEntry(ReadOnlySpan<char>, string)
Writes string content into bundle.
public void WriteEntry(ReadOnlySpan<char> str, string path)
Parameters
strReadOnlySpan<char>String content.
pathstringRelative file path inside bundle.
WriteFile(string, string?)
Writes contents of file into bundle.
public void WriteFile(string path, string? overridePath = null)
Parameters
WriteManifest(BundleManifest)
Writes manifest into bundle.
public void WriteManifest(BundleManifest manifest)
Parameters
manifestBundleManifestPolicy bundle manifest.