public static Func <byte[], BlobCreation> New(BlobRepositoryFactoryContext context) { return(data => { Guid identifier = Guid.NewGuid(); string name = identifier.ToHex(); string hash = data.ToHash(); string path = Path.Combine(context.Location, $"{name}-{hash}"); if (IsValidZipContent(data)) { File.WriteAllBytes(path, data); return new BlobCreation { Success = true, GetBlob = () => BlobFactory.Create(with => { with.Identifier = identifier; with.Path = path; }) }; } return new BlobCreation { Success = false }; }); }
public static Func<byte[], BlobCreation> New(BlobRepositoryFactoryContext context) { return data => { Guid identifier = Guid.NewGuid(); string name = identifier.ToHex(); string hash = data.ToHash(); string path = Path.Combine(context.Location, $"{name}-{hash}"); if (IsValidZipContent(data)) { File.WriteAllBytes(path, data); return new BlobCreation { Success = true, GetBlob = () => BlobFactory.Create(with => { with.Identifier = identifier; with.Path = path; }) }; } return new BlobCreation { Success = false }; }; }
private static Func<Guid, Blob> GetById(BlobRepositoryFactoryContext context) { return identifier => { string name = identifier.ToHex(); string[] files = Directory.GetFiles(context.Location, $"{name}-*"); if (files.Length != 1) return null; return BlobFactory.Create(with => { with.Identifier = identifier; with.Path = files[0]; }); }; }
private static Func <Guid, Blob> GetById(BlobRepositoryFactoryContext context) { return(identifier => { string name = identifier.ToHex(); string[] files = Directory.GetFiles(context.Location, $"{name}-*"); if (files.Length != 1) { return null; } return BlobFactory.Create(with => { with.Identifier = identifier; with.Path = files[0]; }); }); }