项目作者: MrSquirrelyNet

项目描述 :
A simple and easy to use file sizing utility
高级语言: C#
项目地址: git://github.com/MrSquirrelyNet/Squirrel-Sizer.git
创建时间: 2019-07-03T21:03:38Z
项目社区:https://github.com/MrSquirrelyNet/Squirrel-Sizer

开源协议:GNU Lesser General Public License v3.0

下载


Squirrel-Sizer

This is a simple file sizing library.

Goto https://www.nuget.org/packages/SquirrelSizer/

To use it is simple.

You give it a long number and it gives you a string with the size abbreviation suffix.

  1. long number = 1234500;
  2. Sizer.Suffix(number);
  3. // This will output 1kb

or

  1. long number = 1234500;
  2. Sizer.SuffixName(number);
  3. // This will output 1 Kilobyte

It will always give you a number with your string

To stop it from giving you a number

  1. long number = 1234500;
  2. Sizer.Suffix(number, includeNumber: false)
  3. // This will output kb

You have to include the “includeNumber:” part, this is cause of the way I implemented it.

I might change this later.


To change how many decimal places to use it’s easy as well

  1. long number = 1234500;
  2. Sizer.SuffixName(number, 4)
  3. // This will output 1.1773 Kilobyte
  1. long number = 1234500;
  2. Sizer.SuffixName(number, 4, false)
  3. // This will output Kilobyte

To use this with files is even as easy.

  1. Sizer.Suffix("C:\\Path\\To\\File\\file.txt");
  2. // This will output the converted size of the file.

or

  1. Sizer.SuffixName("C:\\Path\\To\\File\\file.txt");
  2. // This will output the converted size of the file.

You can even get the complete size of multiple files

  1. List<string> files = new List<string>() {
  2. "C:\\Path\\To\\File\\file1.txt",
  3. "C:\\Path\\To\\File\\file2.txt",
  4. "C:\\Path\\To\\File\\file3.txt"
  5. };
  6. Sizer.AllSuffix(files);
  7. // This will output the size of all the files in the list

or

  1. List<string> files = new List<string>() {
  2. "C:\\Path\\To\\File\\file1.txt",
  3. "C:\\Path\\To\\File\\file2.txt",
  4. "C:\\Path\\To\\File\\file3.txt"
  5. };
  6. Sizer.AllSuffixName(files);
  7. // This will output the size of all the files in the list