https://github.com/sam0x17/tempdir
Simple creation and automatic deletion of temporary directories in an easy to use crystal shard
https://github.com/sam0x17/tempdir
crystal-language libraries shards temporary temporary-directory
Last synced: about 1 year ago
JSON representation
Simple creation and automatic deletion of temporary directories in an easy to use crystal shard
- Host: GitHub
- URL: https://github.com/sam0x17/tempdir
- Owner: sam0x17
- License: mit
- Created: 2018-05-28T12:39:31.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2019-06-11T10:24:32.000Z (about 7 years ago)
- Last Synced: 2025-03-14T14:21:16.783Z (over 1 year ago)
- Topics: crystal-language, libraries, shards, temporary, temporary-directory
- Language: Crystal
- Size: 8.79 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tempdir
A simple crystal language shard providing on-the-fly unique temporary directories
that are automatically deleted via an `at_exit` hook.
## Installation
Add this to your application's `shard.yml`:
```yaml
dependencies:
tempdir:
github: sam0x17/tempdir
```
## Usage
Simply call the constructor on the `TempDir` class and a temporary directory will be created.
You can pass a string argument to the constructor and this will be used as a prefix to the
directory that gets created. The suffix is populated with a 16-diit random number. When
the current crystal program exits, any directories created by TempDir will be deleted
automatically.
```crystal
require "tempdir"
dir = TempDir.new "my-prefix"
puts dir.to_s # prints "/tmp/my-prefix-7135891628311294"
```
Also available is a block-based invocation style, which will create a temporary directory
that will exist for the lifetime of the block that is passed (when the block ends, the
directory is deleted).
```crystal
require "tempdir"
TempDir.create do |path|
# do stuff with path
end
```
As with the class-based invocation style, you can also pass a prefix:
```crystal
require "tempdir"
TempDir.create("my-prefix") do |path|
# do stuff with path
end
```
## Contributing
1. Fork it ( https://github.com/[your-github-name]/tempdir/fork )
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create a new Pull Request
## Contributors
- [sam0x17](https://github.com/sam0x17) Sam Johnson - creator, maintainer