mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-25 12:16:37 +00:00
refactor(image-stream): rename file variable to imagePath (#1589)
This is a small initial step towards decoupling the image stream handlers from the concept of a "file." Change-Type: patch Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
This commit is contained in:
parent
77c60b91c6
commit
439be1c222
@ -45,19 +45,19 @@ module.exports = {
|
|||||||
* @public
|
* @public
|
||||||
* @memberof handlers
|
* @memberof handlers
|
||||||
*
|
*
|
||||||
* @param {String} file - file path
|
* @param {String} imagePath - image path
|
||||||
* @param {Object} options - options
|
* @param {Object} options - options
|
||||||
* @param {Number} [options.size] - file size
|
* @param {Number} [options.size] - image size
|
||||||
*
|
*
|
||||||
* @fulfil {Object} - image metadata
|
* @fulfil {Object} - image metadata
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
'application/x-bzip2': (file, options) => {
|
'application/x-bzip2': (imagePath, options) => {
|
||||||
return Bluebird.props({
|
return Bluebird.props({
|
||||||
path: file,
|
path: imagePath,
|
||||||
archiveExtension: fileExtensions.getLastFileExtension(file),
|
archiveExtension: fileExtensions.getLastFileExtension(imagePath),
|
||||||
extension: fileExtensions.getPenultimateFileExtension(file),
|
extension: fileExtensions.getPenultimateFileExtension(imagePath),
|
||||||
stream: fs.createReadStream(file),
|
stream: fs.createReadStream(imagePath),
|
||||||
size: {
|
size: {
|
||||||
original: options.size,
|
original: options.size,
|
||||||
final: {
|
final: {
|
||||||
@ -75,20 +75,20 @@ module.exports = {
|
|||||||
* @public
|
* @public
|
||||||
* @memberof handlers
|
* @memberof handlers
|
||||||
*
|
*
|
||||||
* @param {String} file - file path
|
* @param {String} imagePath - image path
|
||||||
* @param {Object} options - options
|
* @param {Object} options - options
|
||||||
* @param {Number} [options.size] - file size
|
* @param {Number} [options.size] - image size
|
||||||
*
|
*
|
||||||
* @fulfil {Object} - image metadata
|
* @fulfil {Object} - image metadata
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
'application/gzip': (file, options) => {
|
'application/gzip': (imagePath, options) => {
|
||||||
return gzip.getUncompressedSize(file).then((uncompressedSize) => {
|
return gzip.getUncompressedSize(imagePath).then((uncompressedSize) => {
|
||||||
return Bluebird.props({
|
return Bluebird.props({
|
||||||
path: file,
|
path: imagePath,
|
||||||
archiveExtension: fileExtensions.getLastFileExtension(file),
|
archiveExtension: fileExtensions.getLastFileExtension(imagePath),
|
||||||
extension: fileExtensions.getPenultimateFileExtension(file),
|
extension: fileExtensions.getPenultimateFileExtension(imagePath),
|
||||||
stream: fs.createReadStream(file),
|
stream: fs.createReadStream(imagePath),
|
||||||
size: {
|
size: {
|
||||||
original: options.size,
|
original: options.size,
|
||||||
final: {
|
final: {
|
||||||
@ -107,24 +107,24 @@ module.exports = {
|
|||||||
* @public
|
* @public
|
||||||
* @memberof handlers
|
* @memberof handlers
|
||||||
*
|
*
|
||||||
* @param {String} file - file path
|
* @param {String} imagePath - image path
|
||||||
* @param {Object} options - options
|
* @param {Object} options - options
|
||||||
* @param {Number} [options.size] - file size
|
* @param {Number} [options.size] - image size
|
||||||
*
|
*
|
||||||
* @fulfil {Object} - image metadata
|
* @fulfil {Object} - image metadata
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
'application/x-xz': (file, options) => {
|
'application/x-xz': (imagePath, options) => {
|
||||||
return fs.openAsync(file, 'r').then((fileDescriptor) => {
|
return fs.openAsync(imagePath, 'r').then((fileDescriptor) => {
|
||||||
return lzma.parseFileIndexFDAsync(fileDescriptor).tap(() => {
|
return lzma.parseFileIndexFDAsync(fileDescriptor).tap(() => {
|
||||||
return fs.closeAsync(fileDescriptor);
|
return fs.closeAsync(fileDescriptor);
|
||||||
});
|
});
|
||||||
}).then((metadata) => {
|
}).then((metadata) => {
|
||||||
return {
|
return {
|
||||||
path: file,
|
path: imagePath,
|
||||||
archiveExtension: fileExtensions.getLastFileExtension(file),
|
archiveExtension: fileExtensions.getLastFileExtension(imagePath),
|
||||||
extension: fileExtensions.getPenultimateFileExtension(file),
|
extension: fileExtensions.getPenultimateFileExtension(imagePath),
|
||||||
stream: fs.createReadStream(file),
|
stream: fs.createReadStream(imagePath),
|
||||||
size: {
|
size: {
|
||||||
original: options.size,
|
original: options.size,
|
||||||
final: {
|
final: {
|
||||||
@ -143,19 +143,19 @@ module.exports = {
|
|||||||
* @public
|
* @public
|
||||||
* @memberof handlers
|
* @memberof handlers
|
||||||
*
|
*
|
||||||
* @param {String} file - file path
|
* @param {String} imagePath - image path
|
||||||
* @param {Object} options - options
|
* @param {Object} options - options
|
||||||
* @param {Number} [options.size] - file size
|
* @param {Number} [options.size] - image size
|
||||||
*
|
*
|
||||||
* @fulfil {Object} - image metadata
|
* @fulfil {Object} - image metadata
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
'application/x-apple-diskimage': (file, options) => {
|
'application/x-apple-diskimage': (imagePath, options) => {
|
||||||
return udif.getUncompressedSizeAsync(file).then((size) => {
|
return udif.getUncompressedSizeAsync(imagePath).then((size) => {
|
||||||
return {
|
return {
|
||||||
path: file,
|
path: imagePath,
|
||||||
extension: fileExtensions.getLastFileExtension(file),
|
extension: fileExtensions.getLastFileExtension(imagePath),
|
||||||
stream: udif.createReadStream(file),
|
stream: udif.createReadStream(imagePath),
|
||||||
size: {
|
size: {
|
||||||
original: options.size,
|
original: options.size,
|
||||||
final: {
|
final: {
|
||||||
@ -169,7 +169,7 @@ module.exports = {
|
|||||||
if (/invalid footer/i.test(error.message)) {
|
if (/invalid footer/i.test(error.message)) {
|
||||||
throw errors.createUserError({
|
throw errors.createUserError({
|
||||||
title: 'Invalid image',
|
title: 'Invalid image',
|
||||||
description: `There was an error reading "${path.basename(file)}". `
|
description: `There was an error reading "${path.basename(imagePath)}". `
|
||||||
+ 'The image does not appear to be a valid Apple Disk Image (dmg), or may have the wrong filename extension.\n\n'
|
+ 'The image does not appear to be a valid Apple Disk Image (dmg), or may have the wrong filename extension.\n\n'
|
||||||
+ `Error: ${error.description || error.message}`
|
+ `Error: ${error.description || error.message}`
|
||||||
});
|
});
|
||||||
@ -184,12 +184,12 @@ module.exports = {
|
|||||||
* @public
|
* @public
|
||||||
* @memberof handlers
|
* @memberof handlers
|
||||||
*
|
*
|
||||||
* @param {String} file - file path
|
* @param {String} imagePath - image path
|
||||||
* @fulfil {Object} - image metadata
|
* @fulfil {Object} - image metadata
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
'application/zip': (file) => {
|
'application/zip': (imagePath) => {
|
||||||
return archive.extractImage(file, zipArchiveHooks);
|
return archive.extractImage(imagePath, zipArchiveHooks);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -198,18 +198,18 @@ module.exports = {
|
|||||||
* @public
|
* @public
|
||||||
* @memberof handlers
|
* @memberof handlers
|
||||||
*
|
*
|
||||||
* @param {String} file - file path
|
* @param {String} imagePath - image path
|
||||||
* @param {Object} options - options
|
* @param {Object} options - options
|
||||||
* @param {Number} [options.size] - file size
|
* @param {Number} [options.size] - image size
|
||||||
*
|
*
|
||||||
* @fulfil {Object} - image metadata
|
* @fulfil {Object} - image metadata
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
'application/octet-stream': (file, options) => {
|
'application/octet-stream': (imagePath, options) => {
|
||||||
return Bluebird.props({
|
return Bluebird.props({
|
||||||
path: file,
|
path: imagePath,
|
||||||
extension: fileExtensions.getLastFileExtension(file),
|
extension: fileExtensions.getLastFileExtension(imagePath),
|
||||||
stream: fs.createReadStream(file),
|
stream: fs.createReadStream(imagePath),
|
||||||
size: {
|
size: {
|
||||||
original: options.size,
|
original: options.size,
|
||||||
final: {
|
final: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user