Nucleus .Net Core CMS

AllowedFileTypeExtensions Class

Namespace: Nucleus.Extensions
Assembly: Nucleus.Extensions.dll
Extension methods for Models.Configuration.AllowedFileType.
GetSample (Stream stream)
Retrieve a 64 byte sample from the start of a stream. If the stream contains less than 64 bytes, retrieve all bytes.
Parameters
Name Type
stream System.IO.Stream
Remarks
This function is used when validating that file contents match the expected signature for the relevant file type/extension. If the stream supports seeking, this function reads 64 bytes from the start of ths stream and then resets the stream position back to 0. If the stream does not support seeking, this function reads 64 bytes from the current position and the stream position will not be reset. Callers which send a stream which cannot seek and which continue to process the stream must account for this by consuming the returned byte[] array.
IsValid (AllowedFileType allowedFileType, Stream stream)
Return whether the bytes in the stream match one or more "allowed" file signatures.
Remarks
This function does not close the stream, the caller must close the stream.
IsValid (String signature, Byte[] sample)
Return whether the bytes in sample match the signature.
Parameters
Name Type
signature String
sample Byte[]
Remarks
The signature is a hex-encoded string. The signature can contain ?? to represent a byte position which is ignored when checking whether sample bytes match the signature.