This repository has been archived by the owner on Sep 1, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
bin/oven
, update readme, change function name.
- Loading branch information
1 parent
f2f99e3
commit 0b43aee
Showing
6 changed files
with
135 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,55 @@ | ||
# openbadges-bakery [![Build Status](https://secure.travis-ci.org/mozilla/openbadges-bakery.png)](http://travis-ci.org/mozilla/openbadges-bakery) | ||
|
||
Provides two methods: | ||
# Install | ||
```bash | ||
$ npm install openbadges-bakery | ||
``` | ||
# CLI Usage | ||
|
||
## Baking | ||
|
||
```bash | ||
$ oven [--in path/to/image.png] [--out path/to/baked-image.png] <data> | ||
``` | ||
If `--out` is not set, the baked image will print to stdout. | ||
|
||
The input file can also be piped into stdin. | ||
|
||
```js | ||
bakery.bake(buffer | stream, callback); | ||
bakery.debake(buffer | stream, callback); | ||
```bash | ||
$ cat path/to/image.png | oven <data> > path/to/baked-image.png | ||
``` | ||
## Extracting | ||
|
||
```bash | ||
$ oven [--in path/to/image.png] --extract | ||
``` | ||
|
||
Same as above, you can also pipe a file to stdin. The data will be printed to stdout. | ||
|
||
# Libary Usage | ||
|
||
## bakery.bake(options callback); | ||
|
||
Bakes some data into an image. | ||
|
||
Options are | ||
- `image`: either a buffer or a stream representing the PNG to bake | ||
- `data`: the data to put into the badge. At this point, it should likely be a URL pointing to a badge assertion | ||
|
||
`callback` has the signature `function(err, imageData)` | ||
|
||
## bakery.debake(image, callback); | ||
|
||
Gets the URL from a baked badge and attempts to retreive the assertion | ||
at the other end. | ||
|
||
`image` should be a stream or a buffer | ||
|
||
`callback` has the signature `function (err, object)` where `object` is expected to be a OpenBadges assertion. | ||
|
||
## bakery.extract(image, callback) | ||
|
||
Gets the data from the baked badge. | ||
|
||
`callback` has the signature `function (err, data)` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env node | ||
|
||
const fs = require('fs'); | ||
const argv = require('optimist').argv; | ||
const stdout = process.stdout; | ||
const stdin = process.stdin; | ||
const stderr = process.stderr; | ||
const bakery = require('../'); | ||
const path = require('path'); | ||
const url = argv._[0]; | ||
const infile = argv.in||argv.infile; | ||
const outfile = argv.out||argv.outfile; | ||
const extract = argv.extract; | ||
|
||
function log(msg) { | ||
stderr.write(msg + '\n'); | ||
} | ||
|
||
if (!url && !extract) { | ||
log('You must pass a url to bake into the image'); | ||
process.exit(1); | ||
} | ||
|
||
var stream; | ||
if (infile) { | ||
stream = fs.createReadStream(path.resolve(infile)); | ||
} else { | ||
stdin.resume(); | ||
stream = stdin; | ||
} | ||
|
||
if (extract) { | ||
bakery.extract(stream, function done(err, data) { | ||
if (err) { | ||
log('there was an error:', err.message); | ||
process.exit(1); | ||
} | ||
stdout.write(data + '\n'); | ||
process.exit(1); | ||
}) | ||
} | ||
|
||
bakery.bake({ | ||
image: stream, | ||
url: url | ||
}, function done(err, baked) { | ||
if (err) { | ||
log('there was an error:', err.message); | ||
process.exit(1); | ||
} | ||
if (outfile) { | ||
fs.writeFileSync(path.resolve(outfile), baked) | ||
} else { | ||
stdout.write(baked); | ||
} | ||
process.exit(0); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.