-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
308 additions
and
23 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
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,47 @@ | ||
/* jshint esversion: 6, node: true */ | ||
|
||
'use strict'; | ||
|
||
const idl = require('@avro/idl'); | ||
const types = require('@avro/types'); | ||
const streams = require('@avro/streams'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
function parse(s, opts) { | ||
let schema; | ||
if (typeof s == 'string' && ~s.indexOf(path.sep) && fs.existsSync(s)) { | ||
// Try interpreting `s` as path to a file contain a JSON schema or an IDL | ||
// protocol. Note that we add the second check to skip primitive references | ||
// (e.g. `"int"`, the most common use-case for `avro.parse`). | ||
const contents = fs.readFileSync(s, {encoding: 'utf8'}); | ||
try { | ||
schema = JSON.parse(contents); | ||
} catch (err) { | ||
schema = idl.assembleProtocolSync(s, opts); | ||
} | ||
} else { | ||
schema = s; | ||
} | ||
if (typeof schema == 'string' && schema !== 'null') { | ||
// This last predicate is to allow `read('null')` to work similarly to | ||
// `read('int')` and other primitives (null needs to be handled separately | ||
// since it is also a valid JSON identifier). | ||
schema = JSON.parse(schema); | ||
} | ||
return types.Type.forSchema(schema); | ||
} | ||
|
||
module.exports = Object.assign( | ||
{ | ||
parse, | ||
Type: types.Type, | ||
types, | ||
createFileDecoder: streams.createFileDecoder, | ||
createFileEncoder: streams.createFileEncoder, | ||
extractFileHeader: streams.extractFileHeader, | ||
streams | ||
}, | ||
require('@avro/services'), | ||
idl | ||
); |
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,20 @@ | ||
/* jshint node: true */ | ||
|
||
'use strict'; | ||
|
||
/** | ||
* Filesystem specifics. | ||
* | ||
* This module contains functions only used by node.js. It is shimmed by | ||
* another module when `avsc` is required from `browserify`. | ||
*/ | ||
|
||
var fs = require('fs'), | ||
path = require('path'); | ||
|
||
|
||
module.exports = { | ||
// Proxy a few methods to better shim them for browserify. | ||
existsSync: fs.existsSync, | ||
readFileSync: fs.readFileSync | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,52 @@ | ||
{ | ||
"name": "avsc", | ||
"version": "6.0.0", | ||
"description": "Avro for JavaScript", | ||
"homepage": "https://github.com/mtth/avsc", | ||
"keywords": [ | ||
"avro", | ||
"avsc", | ||
"binary", | ||
"buffer", | ||
"data", | ||
"decoding", | ||
"encoding", | ||
"interface", | ||
"json", | ||
"marshalling", | ||
"schema", | ||
"serialization", | ||
"type" | ||
], | ||
"files": [ | ||
"lib", | ||
"types" | ||
], | ||
"main": "./lib", | ||
"types": "./types", | ||
"engines": { | ||
"node": ">=7" | ||
}, | ||
"scripts": { | ||
"clean": "rm -rf coverage dist node_modules", | ||
"cover": "nyc mocha", | ||
"coverAndPublish": "nyc npm test && nyc report --reporter=text-lcov | coveralls ../..", | ||
"prepublishOnly": "npm test", | ||
"test": "mocha" | ||
}, | ||
"dependencies": { | ||
"@avro/idl": "^0.1.1", | ||
"@avro/services": "^0.10.0", | ||
"@avro/streams": "^0.2.0", | ||
"@avro/types": "^1.0.2" | ||
}, | ||
"author": { | ||
"name": "Matthieu Monsch", | ||
"email": "mtth@apache.org" | ||
}, | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/mtth/avsc.git" | ||
} | ||
} |
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