Scala 代码(如持续时间)的人类可读大小单位(文件大小) [英] Human readable size units (file sizes) for scala code (like Duration)

查看:50
本文介绍了Scala 代码(如持续时间)的人类可读大小单位(文件大小)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何库为人类可读的文件大小单位(如 持续时间).

Are there any libraries that provide an object/class with implicits conversions (from Int, Long, Float) for human readable file size units (like Duration).

使用Duration,您可以这样做:

11.millis
1.5.minutes
10.hours

我想知道是否有一些图书馆可以让我这样做:

I wonder if there is some library that would allow me to do:

1.gibabyte
1024.megabytes
10.gibibytes
10.GB
50.GiB

我知道我可以自己实现这个,但我不想重新发明轮子.

I know I could implement this myself, but I'm trying to not reinvent the wheel.

推荐答案

我刚刚偶然发现了 squants.正如他们自己的网站所述:

I've just stumbled upon squants. As stated in their own site:

Squants 是数据类型的框架和领域特定的语言(DSL) 用于表示数量、它们的度量单位和它们的维度关系.API 支持类型安全维度分析、改进的领域模型等等.所有类型都是不可变的线程安全.

Squants is a framework of data types and a domain specific language (DSL) for representing Quantities, their Units of Measure, and their Dimensional relationships. The API supports typesafe dimensional analysis, improved domain models and more. All types are immutable and thread-safe.

通过深蹲你可以做到:

10.kib
10.kibibytes
50.mib
100.gib

虽然我不喜欢单位符号都是小写的(即gib而不是GiB)

Although i didn't like that the unit symbols are all lowercase (i.e. gib instead of GiB)

这篇关于Scala 代码(如持续时间)的人类可读大小单位(文件大小)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆