Skip to content

Commit

Permalink
Refactor transformer (processor) service interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchLeaders committed Jan 16, 2024
1 parent fe87204 commit 6464a87
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
33 changes: 15 additions & 18 deletions src/TotkZstd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace NxEditor.TotkPlugin;

public class TotkZstd : IProcessingService
public class TotkZstd : ITransformer
{
private static readonly int _level = Convert.ToInt32(TotkConfig.Shared.ZstdCompressionLevel);

Expand Down Expand Up @@ -46,7 +46,7 @@ public static void ChangeCompressionLevel(int level)
_packCompressor = new(level);
}

public void Process(IEditorFile handle)
public void TransformSource(IEditorFile handle)
{
handle.Source = (
handle.Name.EndsWith(".bcett.byml.zs")
Expand All @@ -55,23 +55,20 @@ public void Process(IEditorFile handle)
).ToArray();
}

public void Reprocess(IEditorFile handle)
public void Transform(ref Span<byte> data, IEditorFile handle)
{
WriteEditorFile baseWrite = handle.Write;
handle.Write = (data) => {
if (handle.Name.EndsWith(".bcett.byml.zs")) {
baseWrite(_bcettCompressor.Wrap(data));
}
else if (handle.Name.EndsWith(".pack.zs")) {
baseWrite(_packCompressor.Wrap(data));
}
else if (handle.Name.EndsWith(".rsizetable.zs")) {
baseWrite(_defaultCompressor.Wrap(data));
}
else {
baseWrite(_commonCompressor.Wrap(data));
}
};
if (handle.Name.EndsWith(".bcett.byml.zs")) {
data = _bcettCompressor.Wrap(data);
}
else if (handle.Name.EndsWith(".pack.zs")) {
data = _packCompressor.Wrap(data);
}
else if (handle.Name.EndsWith(".rsizetable.zs")) {
data = _defaultCompressor.Wrap(data);
}
else {
data = _commonCompressor.Wrap(data);
}
}

public bool IsValid(IEditorFile handle)
Expand Down

0 comments on commit 6464a87

Please sign in to comment.