The perByte() function can be used with both the OneByte and Sustainable Web Design Models. We recommend using this function, as it will return a CO2 value (in grams) for raw data transfer using a given model. It can be used for calculating emissions from websites, file uploads, streaming etc.
import { co2 } from "@tgwf/co2";
const oneByte = new co2({ model: "1byte" });
const emissions = oneByte.perByte(1000000);
Here we are using the OneByte model, and using the perByte() function to check the carbon emissions for transferring 1 million bytes.
The perByte() function accepts the following parameters:
number boolean Optional: if the data being measured is served from a green web host.The perByte() function returns a floating point decimal value which is the amount of CO2e (in grams) calculated using the function.