mirror of
https://github.com/chylex/Brotli-Builder.git
synced 2025-04-15 15:15:42 +02:00
Update BrotliCalc directory lister to support single files & normalize path names
This commit is contained in:
parent
ac27458c38
commit
98831e4785
@ -14,6 +14,7 @@ namespace BrotliCalc.Helpers{
|
||||
static class Brotli{
|
||||
private const int CompressionFileLimit = 2000;
|
||||
private const string CompressedFileExtension = ".br";
|
||||
public const char DirectorySeparator = '/';
|
||||
|
||||
private static readonly Regex RegexCompressionIdentifier = new Regex(@"\.([^.]+)\.br$");
|
||||
private static readonly IntRange QualityRange = new IntRange(0, 11);
|
||||
@ -31,10 +32,17 @@ namespace BrotliCalc.Helpers{
|
||||
}
|
||||
|
||||
public static IEnumerable<BrotliFileGroup> ListPath(string path){
|
||||
if (!File.GetAttributes(path).HasFlag(FileAttributes.Directory)){
|
||||
var name = Path.GetFileName(path) ?? path;
|
||||
var file = new BrotliFile.Uncompressed(path, name);
|
||||
|
||||
return new BrotliFileGroup[]{ new BrotliFileGroup(file, Array.Empty<BrotliFile.Compressed>()) };
|
||||
}
|
||||
|
||||
int fullPathLength = Path.GetFullPath(path).Length;
|
||||
|
||||
string GetRelativePath(string file){
|
||||
return file.Substring(fullPathLength).TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
|
||||
return file.Substring(fullPathLength).Replace(Path.DirectorySeparatorChar, DirectorySeparator).Replace(Path.AltDirectorySeparatorChar, DirectorySeparator).TrimStart(DirectorySeparator);
|
||||
}
|
||||
|
||||
BrotliFile.Compressed ConstructCompressed(string file){
|
||||
|
Loading…
Reference in New Issue
Block a user