code
stringlengths 24
2.07M
| docstring
stringlengths 25
85.3k
| func_name
stringlengths 1
92
| language
stringclasses 1
value | repo
stringlengths 5
64
| path
stringlengths 4
172
| url
stringlengths 44
218
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
clearCaches() {
this.clearLoadCache();
this.clearSearchCache();
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
clearCaches
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
validateConfig() {
const config = this.config;
config.searchPlaces.forEach(place => {
const loaderKey = _path.default.extname(place) || 'noExt';
const loader = config.loaders[loaderKey];
if (!loader) {
throw new Error(`No loader specified for ${getExtensionDescription(place)}, so searchPlaces item "${place}" is invalid`);
}
if (typeof loader !== 'function') {
throw new Error(`loader for ${getExtensionDescription(place)} is not a function (type provided: "${typeof loader}"), so searchPlaces item "${place}" is invalid`);
}
});
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
validateConfig
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
shouldSearchStopWithResult(result) {
if (result === null) return false;
if (result.isEmpty && this.config.ignoreEmptySearchPlaces) return false;
return true;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
shouldSearchStopWithResult
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
nextDirectoryToSearch(currentDir, currentResult) {
if (this.shouldSearchStopWithResult(currentResult)) {
return null;
}
const nextDir = nextDirUp(currentDir);
if (nextDir === currentDir || currentDir === this.config.stopDir) {
return null;
}
return nextDir;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
nextDirectoryToSearch
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
loadPackageProp(filepath, content) {
const parsedContent = loaders_1.loaders.loadJson(filepath, content);
const packagePropValue = (0, getPropertyByPath_1.getPropertyByPath)(parsedContent, this.config.packageProp);
return packagePropValue || null;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
loadPackageProp
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
getLoaderEntryForFile(filepath) {
if (_path.default.basename(filepath) === 'package.json') {
const loader = this.loadPackageProp.bind(this);
return loader;
}
const loaderKey = _path.default.extname(filepath) || 'noExt';
const loader = this.config.loaders[loaderKey];
if (!loader) {
throw new Error(`No loader specified for ${getExtensionDescription(filepath)}`);
}
return loader;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
getLoaderEntryForFile
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
loadedContentToCosmiconfigResult(filepath, loadedContent) {
if (loadedContent === null) {
return null;
}
if (loadedContent === undefined) {
return {
filepath,
config: undefined,
isEmpty: true
};
}
return {
config: loadedContent,
filepath
};
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
loadedContentToCosmiconfigResult
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
validateFilePath(filepath) {
if (!filepath) {
throw new Error('load must pass a non-empty string');
}
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
validateFilePath
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
function nextDirUp(dir) {
return _path.default.dirname(dir);
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
nextDirUp
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
function getExtensionDescription(filepath) {
const ext = _path.default.extname(filepath);
return ext ? `extension "${ext}"` : 'files without extensions';
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
getExtensionDescription
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
_interopRequireDefault
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
async function fsReadFileAsync(pathname, encoding) {
return new Promise((resolve, reject) => {
_fs.default.readFile(pathname, encoding, (error, contents) => {
if (error) {
reject(error);
return;
}
resolve(contents);
});
});
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
fsReadFileAsync
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
async function readFile(filepath, options = {}) {
const throwNotFound = options.throwNotFound === true;
try {
const content = await fsReadFileAsync(filepath, 'utf8');
return content;
} catch (error) {
if (throwNotFound === false && error.code === 'ENOENT') {
return null;
}
throw error;
}
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
readFile
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
function readFileSync(filepath, options = {}) {
const throwNotFound = options.throwNotFound === true;
try {
const content = _fs.default.readFileSync(filepath, 'utf8');
return content;
} catch (error) {
if (throwNotFound === false && error.code === 'ENOENT') {
return null;
}
throw error;
}
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
readFileSync
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
async function cacheWrapper(cache, key, fn) {
const cached = cache.get(key);
if (cached !== undefined) {
return cached;
}
const result = await fn();
cache.set(key, result);
return result;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
cacheWrapper
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
function cacheWrapperSync(cache, key, fn) {
const cached = cache.get(key);
if (cached !== undefined) {
return cached;
}
const result = fn();
cache.set(key, result);
return result;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
cacheWrapperSync
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
async function isType(fsStatType, statsMethodName, filePath) {
if (typeof filePath !== 'string') {
throw new TypeError(`Expected a string, got ${typeof filePath}`);
}
try {
const stats = await promisify(fs[fsStatType])(filePath);
return stats[statsMethodName]();
} catch (error) {
if (error.code === 'ENOENT') {
return false;
}
throw error;
}
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
isType
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
function isTypeSync(fsStatType, statsMethodName, filePath) {
if (typeof filePath !== 'string') {
throw new TypeError(`Expected a string, got ${typeof filePath}`);
}
try {
return fs[fsStatType](filePath)[statsMethodName]();
} catch (error) {
if (error.code === 'ENOENT') {
return false;
}
throw error;
}
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
isTypeSync
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
_interopRequireDefault
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
async function getDirectory(filepath) {
const filePathIsDirectory = await (0, pathType.isDirectory)(filepath);
if (filePathIsDirectory === true) {
return filepath;
}
const directory = _path.default.dirname(filepath);
return directory;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
getDirectory
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
function getDirectorySync(filepath) {
const filePathIsDirectory = (0, pathType.isDirectorySync)(filepath);
if (filePathIsDirectory === true) {
return filepath;
}
const directory = _path.default.dirname(filepath);
return directory;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
getDirectorySync
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
_interopRequireDefault
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
function _asyncIterator(iterable) {
var method;
if (typeof Symbol !== "undefined") {
if (Symbol.asyncIterator) {
method = iterable[Symbol.asyncIterator];
if (method != null) return method.call(iterable);
}
if (Symbol.iterator) {
method = iterable[Symbol.iterator];
if (method != null) return method.call(iterable);
}
}
throw new TypeError("Object is not async iterable");
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
_asyncIterator
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
async search(searchFrom = process.cwd()) {
const startDirectory = await (0, getDirectory_1.getDirectory)(searchFrom);
const result = await this.searchFromDirectory(startDirectory);
return result;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
search
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
async searchFromDirectory(dir) {
const absoluteDir = _path.default.resolve(process.cwd(), dir);
const run = async () => {
const result = await this.searchDirectory(absoluteDir);
const nextDir = this.nextDirectoryToSearch(absoluteDir, result);
if (nextDir) {
return this.searchFromDirectory(nextDir);
}
const transformResult = await this.config.transform(result);
return transformResult;
};
if (this.searchCache) {
return (0, cacheWrapper_1.cacheWrapper)(this.searchCache, absoluteDir, run);
}
return run();
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
searchFromDirectory
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
run = async () => {
const result = await this.searchDirectory(absoluteDir);
const nextDir = this.nextDirectoryToSearch(absoluteDir, result);
if (nextDir) {
return this.searchFromDirectory(nextDir);
}
const transformResult = await this.config.transform(result);
return transformResult;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
run
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
run = async () => {
const result = await this.searchDirectory(absoluteDir);
const nextDir = this.nextDirectoryToSearch(absoluteDir, result);
if (nextDir) {
return this.searchFromDirectory(nextDir);
}
const transformResult = await this.config.transform(result);
return transformResult;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
run
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
async searchDirectory(dir) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError;
try {
for (var _iterator = _asyncIterator(this.config.searchPlaces), _step, _value; _step = await _iterator.next(), _iteratorNormalCompletion = _step.done, _value = await _step.value, !_iteratorNormalCompletion; _iteratorNormalCompletion = true) {
const place = _value;
const placeResult = await this.loadSearchPlace(dir, place);
if (this.shouldSearchStopWithResult(placeResult) === true) {
return placeResult;
}
} // config not found
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
await _iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return null;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
searchDirectory
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
async loadSearchPlace(dir, place) {
const filepath = _path.default.join(dir, place);
const fileContents = await (0, readFile_1.readFile)(filepath);
const result = await this.createCosmiconfigResult(filepath, fileContents);
return result;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
loadSearchPlace
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
async loadFileContent(filepath, content) {
if (content === null) {
return null;
}
if (content.trim() === '') {
return undefined;
}
const loader = this.getLoaderEntryForFile(filepath);
const loaderResult = await loader(filepath, content);
return loaderResult;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
loadFileContent
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
async createCosmiconfigResult(filepath, content) {
const fileContent = await this.loadFileContent(filepath, content);
const result = this.loadedContentToCosmiconfigResult(filepath, fileContent);
return result;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
createCosmiconfigResult
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
async load(filepath) {
this.validateFilePath(filepath);
const absoluteFilePath = _path.default.resolve(process.cwd(), filepath);
const runLoad = async () => {
const fileContents = await (0, readFile_1.readFile)(absoluteFilePath, {
throwNotFound: true
});
const result = await this.createCosmiconfigResult(absoluteFilePath, fileContents);
const transformResult = await this.config.transform(result);
return transformResult;
};
if (this.loadCache) {
return (0, cacheWrapper_1.cacheWrapper)(this.loadCache, absoluteFilePath, runLoad);
}
return runLoad();
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
load
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
runLoad = async () => {
const fileContents = await (0, readFile_1.readFile)(absoluteFilePath, {
throwNotFound: true
});
const result = await this.createCosmiconfigResult(absoluteFilePath, fileContents);
const transformResult = await this.config.transform(result);
return transformResult;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
runLoad
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
runLoad = async () => {
const fileContents = await (0, readFile_1.readFile)(absoluteFilePath, {
throwNotFound: true
});
const result = await this.createCosmiconfigResult(absoluteFilePath, fileContents);
const transformResult = await this.config.transform(result);
return transformResult;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
runLoad
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
_interopRequireDefault
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
searchSync(searchFrom = process.cwd()) {
const startDirectory = (0, getDirectory_1.getDirectorySync)(searchFrom);
const result = this.searchFromDirectorySync(startDirectory);
return result;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
searchSync
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
searchFromDirectorySync(dir) {
const absoluteDir = _path.default.resolve(process.cwd(), dir);
const run = () => {
const result = this.searchDirectorySync(absoluteDir);
const nextDir = this.nextDirectoryToSearch(absoluteDir, result);
if (nextDir) {
return this.searchFromDirectorySync(nextDir);
}
const transformResult = this.config.transform(result);
return transformResult;
};
if (this.searchCache) {
return (0, cacheWrapper_1.cacheWrapperSync)(this.searchCache, absoluteDir, run);
}
return run();
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
searchFromDirectorySync
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
run = () => {
const result = this.searchDirectorySync(absoluteDir);
const nextDir = this.nextDirectoryToSearch(absoluteDir, result);
if (nextDir) {
return this.searchFromDirectorySync(nextDir);
}
const transformResult = this.config.transform(result);
return transformResult;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
run
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
run = () => {
const result = this.searchDirectorySync(absoluteDir);
const nextDir = this.nextDirectoryToSearch(absoluteDir, result);
if (nextDir) {
return this.searchFromDirectorySync(nextDir);
}
const transformResult = this.config.transform(result);
return transformResult;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
run
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
searchDirectorySync(dir) {
for (const place of this.config.searchPlaces) {
const placeResult = this.loadSearchPlaceSync(dir, place);
if (this.shouldSearchStopWithResult(placeResult) === true) {
return placeResult;
}
} // config not found
return null;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
searchDirectorySync
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
loadSearchPlaceSync(dir, place) {
const filepath = _path.default.join(dir, place);
const content = (0, readFile_1.readFileSync)(filepath);
const result = this.createCosmiconfigResultSync(filepath, content);
return result;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
loadSearchPlaceSync
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
loadFileContentSync(filepath, content) {
if (content === null) {
return null;
}
if (content.trim() === '') {
return undefined;
}
const loader = this.getLoaderEntryForFile(filepath);
const loaderResult = loader(filepath, content);
return loaderResult;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
loadFileContentSync
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
createCosmiconfigResultSync(filepath, content) {
const fileContent = this.loadFileContentSync(filepath, content);
const result = this.loadedContentToCosmiconfigResult(filepath, fileContent);
return result;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
createCosmiconfigResultSync
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
loadSync(filepath) {
this.validateFilePath(filepath);
const absoluteFilePath = _path.default.resolve(process.cwd(), filepath);
const runLoadSync = () => {
const content = (0, readFile_1.readFileSync)(absoluteFilePath, {
throwNotFound: true
});
const cosmiconfigResult = this.createCosmiconfigResultSync(absoluteFilePath, content);
const transformResult = this.config.transform(cosmiconfigResult);
return transformResult;
};
if (this.loadCache) {
return (0, cacheWrapper_1.cacheWrapperSync)(this.loadCache, absoluteFilePath, runLoadSync);
}
return runLoadSync();
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
loadSync
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
runLoadSync = () => {
const content = (0, readFile_1.readFileSync)(absoluteFilePath, {
throwNotFound: true
});
const cosmiconfigResult = this.createCosmiconfigResultSync(absoluteFilePath, content);
const transformResult = this.config.transform(cosmiconfigResult);
return transformResult;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
runLoadSync
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
runLoadSync = () => {
const content = (0, readFile_1.readFileSync)(absoluteFilePath, {
throwNotFound: true
});
const cosmiconfigResult = this.createCosmiconfigResultSync(absoluteFilePath, content);
const transformResult = this.config.transform(cosmiconfigResult);
return transformResult;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
runLoadSync
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
} // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
_interopRequireDefault
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
function cosmiconfig(moduleName, options = {}) {
const normalizedOptions = normalizeOptions(moduleName, options);
const explorer = new Explorer_1.Explorer(normalizedOptions);
return {
search: explorer.search.bind(explorer),
load: explorer.load.bind(explorer),
clearLoadCache: explorer.clearLoadCache.bind(explorer),
clearSearchCache: explorer.clearSearchCache.bind(explorer),
clearCaches: explorer.clearCaches.bind(explorer)
};
} // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
cosmiconfig
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
function cosmiconfigSync(moduleName, options = {}) {
const normalizedOptions = normalizeOptions(moduleName, options);
const explorerSync = new ExplorerSync_1.ExplorerSync(normalizedOptions);
return {
search: explorerSync.searchSync.bind(explorerSync),
load: explorerSync.loadSync.bind(explorerSync),
clearLoadCache: explorerSync.clearLoadCache.bind(explorerSync),
clearSearchCache: explorerSync.clearSearchCache.bind(explorerSync),
clearCaches: explorerSync.clearCaches.bind(explorerSync)
};
} // do not allow mutation of default loaders. Make sure it is set inside options
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
cosmiconfigSync
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
function normalizeOptions(moduleName, options) {
const defaults = {
packageProp: moduleName,
searchPlaces: ['package.json', `.${moduleName}rc`, `.${moduleName}rc.json`, `.${moduleName}rc.yaml`, `.${moduleName}rc.yml`, `.${moduleName}rc.js`, `${moduleName}.config.js`],
ignoreEmptySearchPlaces: true,
stopDir: _os.default.homedir(),
cache: true,
transform: identity,
loaders: defaultLoaders
};
const normalizedOptions = Object.assign(Object.assign(Object.assign({}, defaults), options), {}, {
loaders: Object.assign(Object.assign({}, defaults.loaders), options.loaders)
});
return normalizedOptions;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
normalizeOptions
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
identity = function identity(x) {
return x;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
identity
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
identity = function identity(x) {
return x;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
identity
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
function splitPath(path) {
var parts = path.split(/(\/|\\)/);
if (!parts.length) return parts; // when path starts with a slash, the first part is empty string
return !parts[0].length ? parts.slice(1) : parts;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
splitPath
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
function testDir(parts) {
if (parts.length === 0) return cb(null, null);
var p = parts.join('');
exists(path.join(p, clue), function (itdoes) {
if (itdoes) return cb(null, p);
testDir(parts.slice(0, -1));
});
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
testDir
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
function testDir(parts) {
if (parts.length === 0) return null;
var p = parts.join('');
var itdoes = existsSync(path.join(p, clue));
return itdoes ? p : testDir(parts.slice(0, -1));
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
testDir
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
function wrappy(fn, cb) {
if (fn && cb) return wrappy(fn)(cb);
if (typeof fn !== 'function') throw new TypeError('need wrapper function');
Object.keys(fn).forEach(function (k) {
wrapper[k] = fn[k];
});
return wrapper;
function wrapper() {
var args = new Array(arguments.length);
for (var i = 0; i < args.length; i++) {
args[i] = arguments[i];
}
var ret = fn.apply(this, args);
var cb = args[args.length - 1];
if (typeof ret === 'function' && ret !== cb) {
Object.keys(cb).forEach(function (k) {
ret[k] = cb[k];
});
}
return ret;
}
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
wrappy
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
function wrapper() {
var args = new Array(arguments.length);
for (var i = 0; i < args.length; i++) {
args[i] = arguments[i];
}
var ret = fn.apply(this, args);
var cb = args[args.length - 1];
if (typeof ret === 'function' && ret !== cb) {
Object.keys(cb).forEach(function (k) {
ret[k] = cb[k];
});
}
return ret;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
wrapper
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
function once(fn) {
var f = function () {
if (f.called) return f.value;
f.called = true;
return f.value = fn.apply(this, arguments);
};
f.called = false;
return f;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
once
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
f = function () {
if (f.called) return f.value;
f.called = true;
return f.value = fn.apply(this, arguments);
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
f
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
function onceStrict(fn) {
var f = function () {
if (f.called) throw new Error(f.onceError);
f.called = true;
return f.value = fn.apply(this, arguments);
};
var name = fn.name || 'Function wrapped with `once`';
f.onceError = name + " shouldn't be called more than once";
f.called = false;
return f;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
onceStrict
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
f = function () {
if (f.called) throw new Error(f.onceError);
f.called = true;
return f.value = fn.apply(this, arguments);
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
f
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
isRequest = function (stream) {
return stream.setHeader && typeof stream.abort === 'function';
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
isRequest
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
isChildProcess = function (stream) {
return stream.stdio && Array.isArray(stream.stdio) && stream.stdio.length === 3;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
isChildProcess
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
eos = function (stream, opts, callback) {
if (typeof opts === 'function') return eos(stream, null, opts);
if (!opts) opts = {};
callback = once_1(callback || noop);
var ws = stream._writableState;
var rs = stream._readableState;
var readable = opts.readable || opts.readable !== false && stream.readable;
var writable = opts.writable || opts.writable !== false && stream.writable;
var cancelled = false;
var onlegacyfinish = function () {
if (!stream.writable) onfinish();
};
var onfinish = function () {
writable = false;
if (!readable) callback.call(stream);
};
var onend = function () {
readable = false;
if (!writable) callback.call(stream);
};
var onexit = function (exitCode) {
callback.call(stream, exitCode ? new Error('exited with error code: ' + exitCode) : null);
};
var onerror = function (err) {
callback.call(stream, err);
};
var onclose = function () {
process.nextTick(onclosenexttick);
};
var onclosenexttick = function () {
if (cancelled) return;
if (readable && !(rs && rs.ended && !rs.destroyed)) return callback.call(stream, new Error('premature close'));
if (writable && !(ws && ws.ended && !ws.destroyed)) return callback.call(stream, new Error('premature close'));
};
var onrequest = function () {
stream.req.on('finish', onfinish);
};
if (isRequest(stream)) {
stream.on('complete', onfinish);
stream.on('abort', onclose);
if (stream.req) onrequest();else stream.on('request', onrequest);
} else if (writable && !ws) {
// legacy streams
stream.on('end', onlegacyfinish);
stream.on('close', onlegacyfinish);
}
if (isChildProcess(stream)) stream.on('exit', onexit);
stream.on('end', onend);
stream.on('finish', onfinish);
if (opts.error !== false) stream.on('error', onerror);
stream.on('close', onclose);
return function () {
cancelled = true;
stream.removeListener('complete', onfinish);
stream.removeListener('abort', onclose);
stream.removeListener('request', onrequest);
if (stream.req) stream.req.removeListener('finish', onfinish);
stream.removeListener('end', onlegacyfinish);
stream.removeListener('close', onlegacyfinish);
stream.removeListener('finish', onfinish);
stream.removeListener('exit', onexit);
stream.removeListener('end', onend);
stream.removeListener('error', onerror);
stream.removeListener('close', onclose);
};
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
eos
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
onlegacyfinish = function () {
if (!stream.writable) onfinish();
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
onlegacyfinish
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
onfinish = function () {
writable = false;
if (!readable) callback.call(stream);
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
onfinish
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
onend = function () {
readable = false;
if (!writable) callback.call(stream);
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
onend
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
onexit = function (exitCode) {
callback.call(stream, exitCode ? new Error('exited with error code: ' + exitCode) : null);
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
onexit
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
onerror = function (err) {
callback.call(stream, err);
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
onerror
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
onclosenexttick = function () {
if (cancelled) return;
if (readable && !(rs && rs.ended && !rs.destroyed)) return callback.call(stream, new Error('premature close'));
if (writable && !(ws && ws.ended && !ws.destroyed)) return callback.call(stream, new Error('premature close'));
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
onclosenexttick
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
onrequest = function () {
stream.req.on('finish', onfinish);
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
onrequest
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
isFn = function (fn) {
return typeof fn === 'function';
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
isFn
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
isFS = function (stream) {
if (!ancient) return false; // newer node version do not need to care about fs is a special way
if (!fs) return false; // browser
return (stream instanceof (fs.ReadStream || noop$1) || stream instanceof (fs.WriteStream || noop$1)) && isFn(stream.close);
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
isFS
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
isRequest$1 = function (stream) {
return stream.setHeader && isFn(stream.abort);
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
isRequest$1
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
destroyer = function (stream, reading, writing, callback) {
callback = once_1(callback);
var closed = false;
stream.on('close', function () {
closed = true;
});
endOfStream(stream, {
readable: reading,
writable: writing
}, function (err) {
if (err) return callback(err);
closed = true;
callback();
});
var destroyed = false;
return function (err) {
if (closed) return;
if (destroyed) return;
destroyed = true;
if (isFS(stream)) return stream.close(noop$1); // use close for fs streams to avoid fd leaks
if (isRequest$1(stream)) return stream.abort(); // request.destroy just do .end - .abort is what we want
if (isFn(stream.destroy)) return stream.destroy();
callback(err || new Error('stream was destroyed'));
};
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
destroyer
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
pipe = function (from, to) {
return from.pipe(to);
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
pipe
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
pump = function () {
var streams = Array.prototype.slice.call(arguments);
var callback = isFn(streams[streams.length - 1] || noop$1) && streams.pop() || noop$1;
if (Array.isArray(streams[0])) streams = streams[0];
if (streams.length < 2) throw new Error('pump requires two streams per minimum');
var error;
var destroys = streams.map(function (stream, i) {
var reading = i < streams.length - 1;
var writing = i > 0;
return destroyer(stream, reading, writing, function (err) {
if (!error) error = err;
if (err) destroys.forEach(call);
if (reading) return;
destroys.forEach(call);
callback(error);
});
});
return streams.reduce(pipe);
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
pump
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
bufferStream = options => {
options = Object.assign({}, options);
const {
array
} = options;
let {
encoding
} = options;
const isBuffer = encoding === 'buffer';
let objectMode = false;
if (array) {
objectMode = !(encoding || isBuffer);
} else {
encoding = encoding || 'utf8';
}
if (isBuffer) {
encoding = null;
}
const stream = new PassThroughStream({
objectMode
});
if (encoding) {
stream.setEncoding(encoding);
}
let length = 0;
const chunks = [];
stream.on('data', chunk => {
chunks.push(chunk);
if (objectMode) {
length = chunks.length;
} else {
length += chunk.length;
}
});
stream.getBufferedValue = () => {
if (array) {
return chunks;
}
return isBuffer ? Buffer.concat(chunks, length) : chunks.join('');
};
stream.getBufferedLength = () => length;
return stream;
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
bufferStream
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
constructor() {
super('maxBuffer exceeded');
this.name = 'MaxBufferError';
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
constructor
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
async function getStream(inputStream, options) {
if (!inputStream) {
return Promise.reject(new Error('Expected a stream'));
}
options = Object.assign({
maxBuffer: Infinity
}, options);
const {
maxBuffer
} = options;
let stream;
await new Promise((resolve, reject) => {
const rejectPromise = error => {
if (error) {
// A null check
error.bufferedData = stream.getBufferedValue();
}
reject(error);
};
stream = pump_1(inputStream, bufferStream(options), error => {
if (error) {
rejectPromise(error);
return;
}
resolve();
});
stream.on('data', () => {
if (stream.getBufferedLength() > maxBuffer) {
rejectPromise(new MaxBufferError());
}
});
});
return stream.getBufferedValue();
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
getStream
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
rejectPromise = error => {
if (error) {
// A null check
error.bufferedData = stream.getBufferedValue();
}
reject(error);
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
rejectPromise
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
rejectPromise = error => {
if (error) {
// A null check
error.bufferedData = stream.getBufferedValue();
}
reject(error);
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
rejectPromise
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
buffer = (stream, options) => getStream(stream, Object.assign(Object.assign({}, options), {}, {
encoding: 'buffer'
}))
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
buffer
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
array = (stream, options) => getStream(stream, Object.assign(Object.assign({}, options), {}, {
array: true
}))
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
array
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
function checkEnv(obj) {
if (typeof obj === 'string') return !!env[obj];
return Object.keys(obj).every(function (k) {
return env[k] === obj[k];
});
}
|
Returns a Buffer in node and an Uint8Array in browsers
To use the resulting buffer as an image, you'll want to do something like:
const blob = new Blob([buffer], { type: 'image/jpeg' })
document.querySelector('#photo').src = URL.createObjectURL(blob)
|
checkEnv
|
javascript
|
douyu/juno
|
assets/public/js/prettier/v2.0.5/third-party.js
|
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/third-party.js
|
Apache-2.0
|
function loop () {
for (var i = 0; i < 100; i++) {
assert.equal(Math.abs(-i), func(-i))
}
(typeof setImmediate != 'undefined' ? setImmediate : process.nextTick)(loop)
}
|
This example creates an ffi.Callback from the "Math.abs()" JavaScript function
then creates a ffi.ForeignFunction from that callback function pointer.
The result is basically the same as calling "Math.abs()" directly, haha!
This example should basically just run forever, in an endless loop.
This file is a "pummel test" of sorts for:
https://github.com/rbranson/node-ffi/issues/74
We should run this file periodically for a period of ~10 minutes to make sure
it doesn't crash ever.
|
loop
|
javascript
|
node-ffi/node-ffi
|
example/abs.js
|
https://github.com/node-ffi/node-ffi/blob/master/example/abs.js
|
MIT
|
function Callback (retType, argTypes, abi, func) {
debug('creating new Callback')
if (typeof abi === 'function') {
func = abi
abi = void(0)
}
// check args
assert(!!retType, 'expected a return "type" object as the first argument')
assert(Array.isArray(argTypes), 'expected Array of arg "type" objects as the second argument')
assert.equal(typeof func, 'function', 'expected a function as the third argument')
// normalize the "types" (they could be strings, so turn into real type
// instances)
retType = ref.coerceType(retType)
argTypes = argTypes.map(ref.coerceType)
// create the `ffi_cif *` instance
var cif = CIF(retType, argTypes, abi)
var argc = argTypes.length
var callback = _Callback(cif, retType.size, argc, errorReportCallback, function (retval, params) {
debug('Callback function being invoked')
try {
var args = []
for (var i = 0; i < argc; i++) {
var type = argTypes[ i ]
var argPtr = params.readPointer(i * ref.sizeof.pointer, type.size)
argPtr.type = type
args.push(argPtr.deref())
}
// Invoke the user-given function
var result = func.apply(null, args)
try {
ref.set(retval, 0, result, retType)
} catch (e) {
e.message = 'error setting return value - ' + e.message
throw e
}
} catch (e) {
return e
}
})
// store reference to the CIF Buffer so that it doesn't get
// garbage collected before the callback Buffer does
callback._cif = cif;
return callback
}
|
Turns a JavaScript function into a C function pointer.
The function pointer may be used in other C functions that
accept C callback functions.
|
Callback
|
javascript
|
node-ffi/node-ffi
|
lib/callback.js
|
https://github.com/node-ffi/node-ffi/blob/master/lib/callback.js
|
MIT
|
function CIF (rtype, types, abi) {
debug('creating `ffi_cif *` instance')
// the return and arg types are expected to be coerced at this point...
assert(!!rtype, 'expected a return "type" object as the first argument')
assert(Array.isArray(types), 'expected an Array of arg "type" objects as the second argument')
// the buffer that will contain the return `ffi_cif *` instance
var cif = new Buffer(FFI_CIF_SIZE)
var numArgs = types.length
var _argtypesptr = new Buffer(numArgs * POINTER_SIZE)
var _rtypeptr = Type(rtype)
for (var i = 0; i < numArgs; i++) {
var type = types[i]
var ffiType = Type(type)
_argtypesptr.writePointer(ffiType, i * POINTER_SIZE)
}
// prevent GC of the arg type and rtn type buffers (not sure if this is required)
cif.rtnTypePtr = _rtypeptr
cif.argTypesPtr = _argtypesptr
if (typeof abi === 'undefined') {
debug('no ABI specified (this is OK), using FFI_DEFAULT_ABI')
abi = FFI_DEFAULT_ABI
}
var status = ffi_prep_cif(cif, numArgs, _rtypeptr, _argtypesptr, abi)
if (status !== FFI_OK) {
switch (status) {
case FFI_BAD_TYPEDEF:
var err = new Error('ffi_prep_cif() returned an FFI_BAD_TYPEDEF error')
err.code = 'FFI_BAD_TYPEDEF'
err.errno = status
throw err
break;
case FFI_BAD_ABI:
var err = new Error('ffi_prep_cif() returned an FFI_BAD_ABI error')
err.code = 'FFI_BAD_ABI'
err.errno = status
throw err
break;
default:
throw new Error('ffi_prep_cif() returned an error: ' + status)
break;
}
}
return cif
}
|
JS wrapper for the `ffi_prep_cif` function.
Returns a Buffer instance representing a `ffi_cif *` instance.
|
CIF
|
javascript
|
node-ffi/node-ffi
|
lib/cif.js
|
https://github.com/node-ffi/node-ffi/blob/master/lib/cif.js
|
MIT
|
function CIF_var (rtype, types, numFixedArgs, abi) {
debug('creating `ffi_cif *` instance with `ffi_prep_cif_var()`')
// the return and arg types are expected to be coerced at this point...
assert(!!rtype, 'expected a return "type" object as the first argument')
assert(Array.isArray(types), 'expected an Array of arg "type" objects as the second argument')
assert(numFixedArgs >= 1, 'expected the number of fixed arguments to be at least 1')
// the buffer that will contain the return `ffi_cif *` instance
var cif = new Buffer(FFI_CIF_SIZE)
var numTotalArgs = types.length
var _argtypesptr = new Buffer(numTotalArgs * POINTER_SIZE)
var _rtypeptr = Type(rtype)
for (var i = 0; i < numTotalArgs; i++) {
var ffiType = Type(types[i])
_argtypesptr.writePointer(ffiType, i * POINTER_SIZE)
}
// prevent GC of the arg type and rtn type buffers (not sure if this is required)
cif.rtnTypePtr = _rtypeptr
cif.argTypesPtr = _argtypesptr
if (typeof abi === 'undefined') {
debug('no ABI specified (this is OK), using FFI_DEFAULT_ABI')
abi = FFI_DEFAULT_ABI
}
var status = ffi_prep_cif_var(cif, numFixedArgs, numTotalArgs, _rtypeptr, _argtypesptr, abi)
if (status !== FFI_OK) {
switch (status) {
case FFI_BAD_TYPEDEF:
var err = new Error('ffi_prep_cif_var() returned an FFI_BAD_TYPEDEF error')
err.code = 'FFI_BAD_TYPEDEF'
err.errno = status
throw err
break;
case FFI_BAD_ABI:
var err = new Error('ffi_prep_cif_var() returned an FFI_BAD_ABI error')
err.code = 'FFI_BAD_ABI'
err.errno = status
throw err
break;
default:
var err = new Error('ffi_prep_cif_var() returned an error: ' + status)
err.errno = status
throw err
break;
}
}
return cif
}
|
JS wrapper for the `ffi_prep_cif_var` function.
Returns a Buffer instance representing a variadic `ffi_cif *` instance.
|
CIF_var
|
javascript
|
node-ffi/node-ffi
|
lib/cif_var.js
|
https://github.com/node-ffi/node-ffi/blob/master/lib/cif_var.js
|
MIT
|
function DynamicLibrary (path, mode) {
if (!(this instanceof DynamicLibrary)) {
return new DynamicLibrary(path, mode)
}
debug('new DynamicLibrary()', path, mode)
if (null == mode) {
mode = DynamicLibrary.FLAGS.RTLD_LAZY
}
this._handle = dlopen(path, mode)
assert(Buffer.isBuffer(this._handle), 'expected a Buffer instance to be returned from `dlopen()`')
if (this._handle.isNull()) {
var err = this.error()
// THIS CODE IS BASED ON GHC Trac ticket #2615
// http://hackage.haskell.org/trac/ghc/attachment/ticket/2615
// On some systems (e.g., Gentoo Linux) dynamic files (e.g. libc.so)
// contain linker scripts rather than ELF-format object code. This
// code handles the situation by recognizing the real object code
// file name given in the linker script.
// If an "invalid ELF header" error occurs, it is assumed that the
// .so file contains a linker script instead of ELF object code.
// In this case, the code looks for the GROUP ( ... ) linker
// directive. If one is found, the first file name inside the
// parentheses is treated as the name of a dynamic library and the
// code attempts to dlopen that file. If this is also unsuccessful,
// an error message is returned.
// see if the error message is due to an invalid ELF header
var match
if (match = err.match(/^(([^ \t()])+\.so([^ \t:()])*):([ \t])*/)) {
var content = read(match[1], 'ascii')
// try to find a GROUP ( ... ) command
if (match = content.match(/GROUP *\( *(([^ )])+)/)){
return DynamicLibrary.call(this, match[1], mode)
}
}
throw new Error('Dynamic Linking Error: ' + err)
}
}
|
`DynamicLibrary` loads and fetches function pointers for dynamic libraries
(.so, .dylib, etc). After the libray's function pointer is acquired, then you
call `get(symbol)` to retreive a pointer to an exported symbol. You need to
call `get___()` on the pointer to dereference it into its actual value, or
turn the pointer into a callable function with `ForeignFunction`.
|
DynamicLibrary
|
javascript
|
node-ffi/node-ffi
|
lib/dynamic_library.js
|
https://github.com/node-ffi/node-ffi/blob/master/lib/dynamic_library.js
|
MIT
|
function ForeignFunction (funcPtr, returnType, argTypes, abi) {
debug('creating new ForeignFunction', funcPtr)
// check args
assert(Buffer.isBuffer(funcPtr), 'expected Buffer as first argument')
assert(!!returnType, 'expected a return "type" object as the second argument')
assert(Array.isArray(argTypes), 'expected Array of arg "type" objects as the third argument')
// normalize the "types" (they could be strings,
// so turn into real type instances)
returnType = ref.coerceType(returnType)
argTypes = argTypes.map(ref.coerceType)
// create the `ffi_cif *` instance
var cif = CIF(returnType, argTypes, abi)
// create and return the JS proxy function
return _ForeignFunction(cif, funcPtr, returnType, argTypes)
}
|
Represents a foreign function in another library. Manages all of the aspects
of function execution, including marshalling the data parameters for the
function into native types and also unmarshalling the return from function
execution.
|
ForeignFunction
|
javascript
|
node-ffi/node-ffi
|
lib/foreign_function.js
|
https://github.com/node-ffi/node-ffi/blob/master/lib/foreign_function.js
|
MIT
|
function VariadicForeignFunction (funcPtr, returnType, fixedArgTypes, abi) {
debug('creating new VariadicForeignFunction', funcPtr)
// the cache of ForeignFunction instances that this
// VariadicForeignFunction has created so far
var cache = {}
// check args
assert(Buffer.isBuffer(funcPtr), 'expected Buffer as first argument')
assert(!!returnType, 'expected a return "type" object as the second argument')
assert(Array.isArray(fixedArgTypes), 'expected Array of arg "type" objects as the third argument')
var numFixedArgs = fixedArgTypes.length
// normalize the "types" (they could be strings,
// so turn into real type instances)
fixedArgTypes = fixedArgTypes.map(ref.coerceType)
// get the names of the fixed arg types
var fixedKey = fixedArgTypes.map(function (type) {
return getId(type)
})
// what gets returned is another function that needs to be invoked with the rest
// of the variadic types that are being invoked from the function.
function variadic_function_generator () {
debug('variadic_function_generator invoked')
// first get the types of variadic args we are working with
var argTypes = fixedArgTypes.slice()
var key = fixedKey.slice()
for (var i = 0; i < arguments.length; i++) {
var type = ref.coerceType(arguments[i])
argTypes.push(type)
var ffi_type = Type(type)
assert(ffi_type.name)
key.push(getId(type))
}
// now figure out the return type
var rtnType = ref.coerceType(variadic_function_generator.returnType)
var rtnName = getId(rtnType)
assert(rtnName)
// first let's generate the key and see if we got a cache-hit
key = rtnName + key.join('')
var func = cache[key]
if (func) {
debug('cache hit for key:', key)
} else {
// create the `ffi_cif *` instance
debug('creating the variadic ffi_cif instance for key:', key)
var cif = CIF_var(returnType, argTypes, numFixedArgs, abi)
func = cache[key] = _ForeignFunction(cif, funcPtr, rtnType, argTypes)
}
return func
}
// set the return type. we set it as a property of the function generator to
// allow for monkey patching the return value in the very rare case where the
// return type is variadic as well
variadic_function_generator.returnType = returnType
return variadic_function_generator
}
|
For when you want to call to a C function with variable amount of arguments.
i.e. `printf()`.
This function takes care of caching and reusing ForeignFunction instances that
contain the same ffi_type argument signature.
|
VariadicForeignFunction
|
javascript
|
node-ffi/node-ffi
|
lib/foreign_function_var.js
|
https://github.com/node-ffi/node-ffi/blob/master/lib/foreign_function_var.js
|
MIT
|
function variadic_function_generator () {
debug('variadic_function_generator invoked')
// first get the types of variadic args we are working with
var argTypes = fixedArgTypes.slice()
var key = fixedKey.slice()
for (var i = 0; i < arguments.length; i++) {
var type = ref.coerceType(arguments[i])
argTypes.push(type)
var ffi_type = Type(type)
assert(ffi_type.name)
key.push(getId(type))
}
// now figure out the return type
var rtnType = ref.coerceType(variadic_function_generator.returnType)
var rtnName = getId(rtnType)
assert(rtnName)
// first let's generate the key and see if we got a cache-hit
key = rtnName + key.join('')
var func = cache[key]
if (func) {
debug('cache hit for key:', key)
} else {
// create the `ffi_cif *` instance
debug('creating the variadic ffi_cif instance for key:', key)
var cif = CIF_var(returnType, argTypes, numFixedArgs, abi)
func = cache[key] = _ForeignFunction(cif, funcPtr, rtnType, argTypes)
}
return func
}
|
For when you want to call to a C function with variable amount of arguments.
i.e. `printf()`.
This function takes care of caching and reusing ForeignFunction instances that
contain the same ffi_type argument signature.
|
variadic_function_generator
|
javascript
|
node-ffi/node-ffi
|
lib/foreign_function_var.js
|
https://github.com/node-ffi/node-ffi/blob/master/lib/foreign_function_var.js
|
MIT
|
function getId (type) {
if (!type.hasOwnProperty(idKey)) {
type[idKey] = (((1+Math.random())*0x10000)|0).toString(16)
}
return type[idKey]
}
|
For when you want to call to a C function with variable amount of arguments.
i.e. `printf()`.
This function takes care of caching and reusing ForeignFunction instances that
contain the same ffi_type argument signature.
|
getId
|
javascript
|
node-ffi/node-ffi
|
lib/foreign_function_var.js
|
https://github.com/node-ffi/node-ffi/blob/master/lib/foreign_function_var.js
|
MIT
|
function Function (retType, argTypes, abi) {
if (!(this instanceof Function)) {
return new Function(retType, argTypes, abi)
}
debug('creating new FunctionType')
// check args
assert(!!retType, 'expected a return "type" object as the first argument')
assert(Array.isArray(argTypes), 'expected Array of arg "type" objects as the second argument')
// normalize the "types" (they could be strings, so turn into real type
// instances)
this.retType = ref.coerceType(retType)
this.argTypes = argTypes.map(ref.coerceType)
this.abi = null == abi ? bindings.FFI_DEFAULT_ABI : abi
}
|
Creates and returns a "type" object for a C "function pointer".
@api public
|
Function
|
javascript
|
node-ffi/node-ffi
|
lib/function.js
|
https://github.com/node-ffi/node-ffi/blob/master/lib/function.js
|
MIT
|
function Library (libfile, funcs, lib) {
debug('creating Library object for', libfile)
if (libfile && libfile.indexOf(EXT) === -1) {
debug('appending library extension to library name', EXT)
libfile += EXT
}
if (!lib) {
lib = {}
}
var dl = new DynamicLibrary(libfile || null, RTLD_NOW)
Object.keys(funcs || {}).forEach(function (func) {
debug('defining function', func)
var fptr = dl.get(func)
, info = funcs[func]
if (fptr.isNull()) {
throw new Error('Library: "' + libfile
+ '" returned NULL function pointer for "' + func + '"')
}
var resultType = info[0]
, paramTypes = info[1]
, fopts = info[2]
, abi = fopts && fopts.abi
, async = fopts && fopts.async
, varargs = fopts && fopts.varargs
if (varargs) {
lib[func] = VariadicForeignFunction(fptr, resultType, paramTypes, abi)
} else {
var ff = ForeignFunction(fptr, resultType, paramTypes, abi)
lib[func] = async ? ff.async : ff
}
})
return lib
}
|
Provides a friendly abstraction/API on-top of DynamicLibrary and
ForeignFunction.
|
Library
|
javascript
|
node-ffi/node-ffi
|
lib/library.js
|
https://github.com/node-ffi/node-ffi/blob/master/lib/library.js
|
MIT
|
function Type (type) {
type = ref.coerceType(type)
debug('Type()', type.name || type)
assert(type.indirection >= 1, 'invalid "type" given: ' + (type.name || type))
var rtn
// first we assume it's a regular "type". if the "indirection" is greater than
// 1, then we can just use "pointer" ffi_type, otherwise we hope "ffi_type" is
// set
if (type.indirection === 1) {
rtn = type.ffi_type
} else {
rtn = bindings.FFI_TYPES.pointer
}
// if "rtn" isn't set (ffi_type was not set) then we check for "ref-array" type
if (!rtn && type.type) {
// got a "ref-array" type
// passing arrays to C functions are always by reference, so we use "pointer"
rtn = bindings.FFI_TYPES.pointer
}
if (!rtn && type.fields) {
// got a "ref-struct" type
// need to create the `ffi_type` instance manually
debug('creating an `ffi_type` for given "ref-struct" type')
var fields = type.fields
, fieldNames = Object.keys(fields)
, numFields = fieldNames.length
, numElements = 0
, ffi_type = new FFI_TYPE
, i = 0
, field
, ffi_type_ptr
// these are the "ffi_type" values expected for a struct
ffi_type.size = 0
ffi_type.alignment = 0
ffi_type.type = 13 // FFI_TYPE_STRUCT
// first we have to figure out the number of "elements" that will go in the
// array. this would normally just be "numFields" but we also have to account
// for arrays, which each act as their own element
for (i = 0; i < numFields; i++) {
field = fields[fieldNames[i]]
if (field.type.fixedLength > 0) {
// a fixed-length "ref-array" type
numElements += field.type.fixedLength
} else {
numElements += 1
}
}
// hand-crafting a null-terminated array here.
// XXX: use "ref-array"?
var size = ref.sizeof.pointer * (numElements + 1) // +1 because of the NULL terminator
var elements = ffi_type.elements = new Buffer(size)
var index = 0
for (i = 0; i < numFields; i++) {
field = fields[fieldNames[i]]
if (field.type.fixedLength > 0) {
// a fixed-length "ref-array" type
ffi_type_ptr = Type(field.type.type)
for (var j = 0; j < field.type.fixedLength; j++) {
elements.writePointer(ffi_type_ptr, (index++) * ref.sizeof.pointer)
}
} else {
ffi_type_ptr = Type(field.type)
elements.writePointer(ffi_type_ptr, (index++) * ref.sizeof.pointer)
}
}
// final NULL pointer to terminate the Array
elements.writePointer(ref.NULL, index * ref.sizeof.pointer)
// also set the `ffi_type` property to that it's cached for next time
rtn = type.ffi_type = ffi_type.ref()
}
if (!rtn && type.name) {
// handle "ref" types other than the set that node-ffi is using (i.e.
// a separate copy)
if ('CString' == type.name) {
rtn = type.ffi_type = bindings.FFI_TYPES.pointer
} else {
var cur = type
while (!rtn && cur) {
rtn = cur.ffi_type = bindings.FFI_TYPES[cur.name]
cur = Object.getPrototypeOf(cur)
}
}
}
assert(rtn, 'Could not determine the `ffi_type` instance for type: ' + (type.name || type))
debug('returning `ffi_type`', rtn.name)
return rtn
}
|
Returns a `ffi_type *` Buffer appropriate for the given "type".
@param {Type|String} type A "ref" type (or string) to get the `ffi_type` for
@return {Buffer} A buffer pointing to a `ffi_type` instance for "type"
@api private
|
Type
|
javascript
|
node-ffi/node-ffi
|
lib/type.js
|
https://github.com/node-ffi/node-ffi/blob/master/lib/type.js
|
MIT
|
proxy = function () {
debug('invoking proxy function')
if (arguments.length !== numArgs) {
throw new TypeError('Expected ' + numArgs +
' arguments, got ' + arguments.length)
}
// storage buffers for input arguments and the return value
var result = new Buffer(resultSize)
, argsList = new Buffer(argsArraySize)
// write arguments to storage areas
var i, argType, val, valPtr
try {
for (i = 0; i < numArgs; i++) {
argType = argTypes[i]
val = arguments[i]
valPtr = ref.alloc(argType, val)
argsList.writePointer(valPtr, i * POINTER_SIZE)
}
} catch (e) {
e.message = 'error setting argument ' + i + ' - ' + e.message
throw e
}
// invoke the `ffi_call()` function
bindings.ffi_call(cif, funcPtr, result, argsList)
result.type = returnType
return result.deref()
}
|
This is the actual JS function that gets returned.
It handles marshalling input arguments into C values,
and unmarshalling the return value back into a JS value
|
proxy
|
javascript
|
node-ffi/node-ffi
|
lib/_foreign_function.js
|
https://github.com/node-ffi/node-ffi/blob/master/lib/_foreign_function.js
|
MIT
|
function finish () {
kill()
gc() // now ensure the inner "cb" Buffer is collected
// should throw an Error asynchronously!,
// because the callback has been garbage collected.
// hijack the "uncaughtException" event for this test
var listeners = process.listeners('uncaughtException').slice()
process.removeAllListeners('uncaughtException')
process.once('uncaughtException', function (e) {
var err
try {
assert(/ffi/.test(e.message))
} catch (ae) {
err = ae
}
done(err)
listeners.forEach(function (fn) {
process.on('uncaughtException', fn)
})
})
bindings.call_cb_from_thread()
}
|
We should make sure that callbacks or errors gets propagated back to node's main thread
when it called on a non libuv native thread.
See: https://github.com/node-ffi/node-ffi/issues/199
|
finish
|
javascript
|
node-ffi/node-ffi
|
test/callback.js
|
https://github.com/node-ffi/node-ffi/blob/master/test/callback.js
|
MIT
|
function finish () {
bindings.call_cb()
assert.equal(4, invokeCount)
kill()
gc() // now ensure the inner "cb" Buffer is collected
// should throw an Error synchronously
try {
bindings.call_cb()
assert(false) // shouldn't get here
} catch (e) {
assert(/ffi/.test(e.message))
}
done()
}
|
See https://github.com/rbranson/node-ffi/issues/72.
This is a tough issue. If we pass the ffi_closure Buffer to some foreign
C function, we really don't know *when* it's safe to dispose of the Buffer,
so it's left up to the developer.
In this case, we wrap the responsibility in a simple "kill()" function
that, when called, destroys of its references to the ffi_closure Buffer.
|
finish
|
javascript
|
node-ffi/node-ffi
|
test/callback.js
|
https://github.com/node-ffi/node-ffi/blob/master/test/callback.js
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.