douzhang3822
douzhang3822
2016-11-24 22:53
浏览 53
已采纳

在GO中获取实际文件大小与表观大小

"fs.sys.Size" (fs being fileStat in the os package) returns the apparent size of a file. This isn't ideal when dealing with sparse files.

Is there a way to get the actual file size in GO? Or all applications are bound to get the converted metadata that represent empty blocks as real ones?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongwang788787
    dongwang788787 2016-11-25 15:16
    已采纳

    Looks like the Stat_t structure filled using stat/fstat calls from the Syscall package is all you need. Just multiply Blocks by 512 to get the disk space consumed.

    点赞 评论

相关推荐