C# Class kOS.Safe.Persistence.PersistenceUtilities

ファイルを表示 Open project: KSP-KOS/KOS Class Usage Examples

Public Properties

Property Type Description
GzipHeader byte[]

Public Methods

Method Description
CharNeedsEncoding ( char character ) : bool

Returns true if the character has to be encoded and cannot be dumped into a persistence file as-is.

CookedFilename ( string fileName, string extensionName, bool trusted = false ) : string

This is both for error checking and blessing of user-created filenames, and to tack on a filename extension if there is none present.


Returns a version of the filename in which it has had the file extension added unless the filename already has any sort of file extension, in which case nothing is changed about it. If every place where the auto- extension-appending is attempted is done via this method, then it will never end up adding an extension when an explicit one exists already.

DecodeBase64ToBinary ( string input ) : byte[]
DecodeLine ( string input ) : string
EncodeBase64 ( byte input ) : string
EncodeLine ( string input ) : string
IdentifyCategory ( byte firstBytes ) : FileCategory

Given the first few bytes of content, decide what the FileCategory should be, based on what's in the Content.
This should be called before deciding how to set the content.

IsBinary ( FileCategory category ) : bool

Method Details

CharNeedsEncoding() public static method

Returns true if the character has to be encoded and cannot be dumped into a persistence file as-is.
public static CharNeedsEncoding ( char character ) : bool
character char character to test
return bool

CookedFilename() public static method

This is both for error checking and blessing of user-created filenames, and to tack on a filename extension if there is none present.


Returns a version of the filename in which it has had the file extension added unless the filename already has any sort of file extension, in which case nothing is changed about it. If every place where the auto- extension-appending is attempted is done via this method, then it will never end up adding an extension when an explicit one exists already.
public static CookedFilename ( string fileName, string extensionName, bool trusted = false ) : string
fileName string Filename to maybe change. Can be full path or just the filename.
extensionName string Extension to add if there is none already.
trusted bool True if the filename is internally generated (and therefore allowed to /// have paths in it). False if the filename is from a user-land string (and therefore allowing /// a name that walks the directory tree is a security hole.)
return string

DecodeBase64ToBinary() public static method

public static DecodeBase64ToBinary ( string input ) : byte[]
input string
return byte[]

DecodeLine() public static method

public static DecodeLine ( string input ) : string
input string
return string

EncodeBase64() public static method

public static EncodeBase64 ( byte input ) : string
input byte
return string

EncodeLine() public static method

public static EncodeLine ( string input ) : string
input string
return string

IdentifyCategory() public static method

Given the first few bytes of content, decide what the FileCategory should be, based on what's in the Content.
This should be called before deciding how to set the content.
public static IdentifyCategory ( byte firstBytes ) : FileCategory
firstBytes byte At least the first four bytes of the file read in binary form - can be longer if you wish
return FileCategory

IsBinary() public static method

public static IsBinary ( FileCategory category ) : bool
category FileCategory
return bool

Property Details

GzipHeader public_oe static_oe property

public static byte[] GzipHeader
return byte[]