Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
github.com/ylin610/units
This package provides type Bytes
, which implements fmt.Formatter
and can be easily formatted to various human-readable string using std fmt
package.
It also has some mathematics methods to modify the value. See example_test.go.
The formatting result typically consists of a number and a unit.
There are binary units (kiB
, MiB
, GiB
and TiB
), decimal units (kB
, MB
, GB
and TB
) and base unit B
. Further reading here.
When calculating the output number, binary units are used by default. You can switch to decimal units by adding the #
flag.
Why is there no PiB/PB
? TiB/TB
is sufficient for most cases, and many non-technical people are not familiar with PiB/PB
.
s
: format to an integer number and a proper unit.
fmt.Sprintf("%s", units.Bytes(1023)) // 1023B
fmt.Sprintf("%s", units.Bytes(1024)) // 1kiB
fmt.Sprintf("%s", units.Bytes(1025)) // 1kiB
f
: format to a float number and a proper unit, default precision is 1.
fmt.Sprintf("%f", units.Bytes(1023)) // 1023.0B
fmt.Sprintf("%f", units.Bytes(1024)) // 1.0kiB
fmt.Sprintf("%f", units.Bytes(1150)) // 1.1kiB
v
: equal to s
.
k
: format to an integer number with the unit kiB
.
fmt.Sprintf("%k", units.Bytes(1<<9)) // 0B
fmt.Sprintf("%k", units.Bytes(1<<10)) // 1kiB
fmt.Sprintf("%k", units.Bytes(1<<20)) // 1024kiB
m
: format to an integer number with the unit MiB
.
g
: format to an integer number with the unit GiB
.
t
: format to an integer number with the unit TiB
.
#
: use decimal units.
fmt.Sprintf("%f", 10*units.KiB) // 10.0kiB
fmt.Sprintf("%#f", 10*units.KiB) // 10.2kB
: (space) do not output the unit.
fmt.Sprintf("%s", units.KiB) // 1kiB
fmt.Sprintf("% s", units.KiB) // 1
Sign for numbers (+
), left-justify (-
) and zero padding (0
) are not supported.
The width includes the unit.
fmt.Sprintf("%4s", units.KiB) // " 1kiB"
fmt.Sprintf("%8.2f", units.KiB) // " 1.00kiB"
fmt.Sprintf("% 8.2f", units.KiB) // " 1.00"
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.