Node.js:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
第217行: 第217行:
=== RIFF ===
=== RIFF ===
资源互换文件格式(ResourcesInterchange FileFormat)
资源互换文件格式(ResourcesInterchange FileFormat)
=== 单位换算 ===
==== base64 - kb ====
{{leftrightflex|<syntaxhighlight lang="javascript">
const size = (base64) => {
  return (base64.length/1024).toFixed(2);
};
console.log(size(Buffer.from('kangkk', 'utf8').toString('base64')));
// or
const countBase64Size = (base64url) => {
  // 原来的字符流大小,单位为字节
  const strLength = base64url.length;
  // 计算后得到的文件流大小,单位为字节
  const fileLength = parseInt(strLength - (strLength / 8) * 2);
  // 由字节转换为 kb
  const size = (fileLength / 1024).toFixed(2);
  // 转成字符串
  const sizeStr = size + '';
  // 获取小数点处的索引
  const index = sizeStr.indexOf('.');
  // 获取小数点后两位的值
  const dou = sizeStr.substr(index + 1, 2);
  // 判断后两位是否为 00,如果是则删除 00
  if (dou === '00') {
    return sizeStr.substring(0, index) + sizeStr.substr(index + 3, 2);
  }
  return size;
};
console.log(countBase64Size(Buffer.from('kangkk', 'utf8').toString('base64')));</syntaxhighlight>|{{consoleout|<pre>
0.01
0.01
</pre>}}}}


== 线程 ==
== 线程 ==