From 0058d4ca578ce60a2e0a46a5b93c78a27001f01e Mon Sep 17 00:00:00 2001 From: Erik Unger Date: Wed, 27 Nov 2024 08:21:36 +0100 Subject: [PATCH] added MemFile.WithName and WithData --- memfile.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/memfile.go b/memfile.go index e32f6ac..3180345 100644 --- a/memfile.go +++ b/memfile.go @@ -156,6 +156,18 @@ func (f MemFile) Name() string { return f.FileName } +// WithName returns a MemFile with the passed name +// and the same shared data as the original MemFile. +func (f MemFile) WithName(name string) MemFile { + return MemFile{FileName: name, FileData: f.FileData} +} + +// WithData returns a MemFile with the passed data +// and the same name as the original MemFile. +func (f MemFile) WithData(data []byte) MemFile { + return MemFile{FileName: f.FileName, FileData: data} +} + // Ext returns the extension of file name including the point, or an empty string. func (f MemFile) Ext() string { return fsimpl.Ext(f.FileName, "")