Skip to content
This repository was archived by the owner on Nov 24, 2020. It is now read-only.

Add create_thin classmethod to Partition #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Wolf480pl
Copy link

@Wolf480pl Wolf480pl commented Aug 23, 2017

Add a create_thin classmethod that will allow creating partitions with specified file sizes and paths, but without allocating any disk space.

Also turn the allocate staticmethod into a classmethod for consistency.

Add a create_thin classmethod that will allow creating
partitions with specified file sizes and paths, but
without allocating any disk space.
dir_path = os.path.dirname(path)
os.makedirs(dir_path, exist_ok=True)

# Create empty file
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment should say "Create the file if not existing" or something

return cls(paths, chunk_size=chunk_size)

@classmethod
def create_thin(cls, paths, sizes, chunk_size=DEFAULT_CHUNK_SIZE):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe sparse instead of thin? thin is not obvious (at least to me).

os.makedirs(dir_path, exist_ok=True)

# Create empty file
open(path, 'a+b').close()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Truncate?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants