{"id":20122828,"url":"https://github.com/freaky/rust-filesize","last_synced_at":"2025-05-06T16:33:11.631Z","repository":{"id":57629237,"uuid":"184808506","full_name":"Freaky/rust-filesize","owner":"Freaky","description":"Physical disk use retrieval","archived":false,"fork":false,"pushed_at":"2020-03-19T04:49:36.000Z","size":14,"stargazers_count":12,"open_issues_count":1,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-31T11:25:12.388Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Freaky.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-03T19:16:50.000Z","updated_at":"2024-08-14T15:31:53.000Z","dependencies_parsed_at":"2022-09-26T20:10:56.111Z","dependency_job_id":null,"html_url":"https://github.com/Freaky/rust-filesize","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Freaky%2Frust-filesize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Freaky%2Frust-filesize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Freaky%2Frust-filesize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Freaky%2Frust-filesize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Freaky","download_url":"https://codeload.github.com/Freaky/rust-filesize/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224516748,"owners_count":17324398,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T19:41:20.820Z","updated_at":"2024-11-13T19:41:21.432Z","avatar_url":"https://github.com/Freaky.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Cargo](https://img.shields.io/crates/v/filesize.svg)][crate]\n[![Documentation](https://docs.rs/filesize/badge.svg)][docs]\n[![Build Status](https://travis-ci.org/Freaky/rust-filesize.svg?branch=master)](https://travis-ci.org/Freaky/rust-filesize)\n[![CI](https://github.com/Freaky/rust-filesize/workflows/build/badge.svg)][ci]\n\n# filesize\n\nCross-platform physical disk space use retrieval for Rust.\n\n## Synopsis\n\n```rust\npub trait PathExt {\n    fn size_on_disk(\u0026self) -\u003e std::io::Result\u003cu64\u003e;\n    fn size_on_disk_fast(\u0026self, metadata: \u0026Metadata) -\u003e std::io::Result\u003cu64\u003e;\n}\nimpl PathExt for std::path::Path;\n\npub fn file_real_size\u003cP: AsRef\u003cstd::path::Path\u003e\u003e(path: P) -\u003e std::io::Result\u003cu64\u003e;\npub fn file_real_size_fast\u003cP: AsRef\u003cstd::path::Path\u003e\u003e(\n    path: P,\n    metadata: \u0026Metadata\n) -\u003e std::io::Result\u003cu64\u003e;\n```\n\n## Description\n\n`filesize` abstracts platform-specific methods of determining the real space used\nby files, taking into account filesystem compression and sparse files.\n\nIt provides two standalone functions, `file_real_size`, and `file_real_size_fast`,\nand as of version 0.2, a `std::path::Path` extension trait offering identical\nfunctions named `size_on_disk` and `size_on_disk_fast`.\n\nThe `_fast` variants accept a `std::fs::Metadata` reference which will be used\nto cheaply calculate the size on disk if the platform supports that.  This is\nintended for cases such as directory traversal, where metadata is available\nanyway, and where metadata is needed for other purposes.\n\n## Example\n\n```rust\nuse std::path::Path;\nuse filesize::PathExt;\n\nlet path = Path::new(\"Cargo.toml\");\nlet metadata = path.symlink_metadata()?;\n\nlet realsize = path.size_on_disk()?;\nlet realsize = path.size_on_disk_fast(\u0026metadata)?;\n\n// Older interface\nuse filesize::{file_real_size, file_real_size_fast};\n\nlet realsize = file_real_size(path)?;\nlet realsize = file_real_size_fast(path, \u0026metadata)?;\n```\n\n## Platform-specific Behaviour\n\nOn Unix platforms this is a thin wrapper around [`std::fs::symlink_metadata()`]\nand [`std::os::unix::fs::MetadataExt`], simply returning `blocks() * 512`.  The\n`_fast` functions disregard the file path entirely and use the passed metadata\ndirectly.\n\nOn Windows, it wraps [`GetCompressedFileSizeW()`], and the `_fast` functions\ndisregard the passed metadata entirely.\n\nOn any other platforms, it wraps [`std::fs::symlink_metadata()`] and only returns\n`len()`, while the `_fast` variants also disregard the path and use the passed \nmetadata directly.\n\n\n[`GetCompressedFileSizeW()`]: https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getcompressedfilesizew\n[`std::fs::symlink_metadata()`]: https://doc.rust-lang.org/std/fs/fn.symlink_metadata.html\n[`std::os::unix::fs::MetadataExt`]: https://doc.rust-lang.org/std/os/unix/fs/trait.MetadataExt.html\n[crate]: https://crates.io/crates/filesize\n[docs]: https://docs.rs/filesize\n[ci]: https://github.com/Freaky/rust-filesize/actions?query=workflow%3Abuild\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreaky%2Frust-filesize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffreaky%2Frust-filesize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreaky%2Frust-filesize/lists"}