RandomFileTree icon indicating copy to clipboard operation
RandomFileTree copied to clipboard

Files with content

Open dverzolla opened this issue 5 years ago • 5 comments

First of all congrats for your project.

That's not actually an issue, it's more a feature question.

I would like to know if there's any idea to implement files with fake data inside, an option that I could set the file size or even better, size variation, like: (size variation and unit).

-sv 100-1000 -u [K|M|G]

Thank you

dverzolla avatar Dec 12 '20 21:12 dverzolla

Hi @dverzolla

Some time ago @BubaVV implemented a payload feature to add content to the files. There's an example in the readme. Basically you write a quick function payload that returns content for the files. In your case you could probably simply do something like

# THIS CODE HASN'T BEEN TESTED

import random

def payload(*args):
    # Write letter 'a' randomly many times
    return "a" * random.randrange(100, 1000)

I don't have much time in the next few weeks but if you find a quick solution that works for you, we could include it in the package (PRs welcome).

klieret avatar Dec 13 '20 09:12 klieret

Hey @klieret thanks for sharing this, I'll take a look. I'd like to do a PR, however I'm tied in some projects and unfortunately won't have time.

Regards

dverzolla avatar Dec 16 '20 19:12 dverzolla

(You can also share a code snippet if you figured something out :) )

klieret avatar Dec 17 '20 11:12 klieret

(You can also share a code snippet if you figured something out :) )

I am using this shell script to create files: https://gist.github.com/patrickt010/1a5ce16a7fe33e97a0ab

dverzolla avatar Dec 17 '20 20:12 dverzolla

The API you chose for the payload means that you have to re-implement part of the tree generation. That's not really convenient. For example, I don't see how, with that API, I can guarantee the number of files generated as specified with the iterative_gaussian_tree() function. Maybe I missed something.

I would have expected the payload function to receive a path to file, and the payload function would simply write something in the file. Which does not prevent you from doing the copy of template files you put in your example if you will.

The API would look like this.

def payload(path: Path) -> None:
    with open('/dev/random', 'rb') as source:
        path.write_bytes(source.read(100))

We could return the number of bytes written or the path if written into or something like that if necessary.

cansjt avatar Nov 02 '21 08:11 cansjt