-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Refactor commands creation
- Loading branch information
Showing
5 changed files
with
96 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,73 @@ | ||
import { SevenZipStream } from './stream.js' | ||
import { | ||
matchBodyHash, | ||
matchBodyList, | ||
matchBodySymbol, | ||
matchEndOfBodyHyphen, | ||
matchEndOfBodySymbol, | ||
matchEndOfHeadersHyphen, | ||
matchEndOfHeadersSymbol | ||
} from './parser.js' | ||
|
||
function setTarget (opts, target) { | ||
const isTargetMultiple = (Array.isArray(target)) | ||
if (isTargetMultiple) { | ||
opts._commandArgs = opts._commandArgs.concat(target) | ||
} else if (target) { | ||
opts._commandArgs.push(target) | ||
} | ||
return opts | ||
// | ||
// Stream API | ||
// ========== | ||
// | ||
|
||
export function add (archive, source, options) { | ||
return getStreamStandard('a', archive, source, options)._setStandardParsers() | ||
} | ||
|
||
function commandStandard (commandLetter, archive, source, options) { | ||
export function remove (archive, source, options) { | ||
return getStreamStandard('d', archive, source, options)._setStandardParsers() | ||
} | ||
|
||
export function extract (archive, output, cherryPick, options) { | ||
return getStreamExtract('e', archive, output, cherryPick, options)._setStandardParsers() | ||
} | ||
|
||
export function extractFull (archive, output, cherryPick, options) { | ||
return getStreamExtract('x', archive, output, cherryPick, options)._setStandardParsers() | ||
} | ||
|
||
export function hash (target, options) { | ||
return getStreamHash('h', target, options)._setHashParsers() | ||
} | ||
|
||
export function list (archive, target, options) { | ||
return getStreamStandard('l', archive, target, options)._setListParsers() | ||
} | ||
|
||
// | ||
// Library | ||
// ======= | ||
// | ||
|
||
function getStreamStandard (commandLetter, archive, source, options) { | ||
let opts = Object.assign({}, options) | ||
opts._commandArgs = [commandLetter] | ||
opts._commandArgs.push(archive) | ||
opts = setTarget(opts, source) | ||
opts._matchBodyData = matchBodySymbol | ||
opts._matchEndOfHeaders = matchEndOfHeadersSymbol | ||
opts._matchEndOfBody = matchEndOfBodySymbol | ||
const stream = new SevenZipStream(opts) | ||
let stream = new SevenZipStream(opts) | ||
return stream | ||
} | ||
|
||
function commandExtract (commandLetter, archive, output, target, options) { | ||
function getStreamExtract (commandLetter, archive, output, target, options) { | ||
let opts = Object.assign({}, options) | ||
opts._commandArgs = [commandLetter] | ||
opts._commandArgs.push(archive) | ||
if (output) { | ||
opts['o'] = output | ||
} | ||
opts = setTarget(opts, target) | ||
opts._matchBodyData = matchBodySymbol | ||
opts._matchEndOfHeaders = matchEndOfHeadersSymbol | ||
opts._matchEndOfBody = matchEndOfBodySymbol | ||
const stream = new SevenZipStream(opts) | ||
let stream = new SevenZipStream(opts) | ||
return stream | ||
} | ||
|
||
function commandHash (commandLetter, target, options) { | ||
function getStreamHash (commandLetter, target, options) { | ||
let opts = Object.assign({}, options) | ||
opts._commandArgs = [commandLetter] | ||
opts = setTarget(opts, target) | ||
opts._matchBodyData = matchBodyHash | ||
opts._matchEndOfHeaders = matchEndOfHeadersHyphen | ||
opts._matchEndOfBody = matchEndOfBodyHyphen | ||
const stream = new SevenZipStream(opts) | ||
return stream | ||
} | ||
|
||
function commandList (commandLetter, archive, source, options) { | ||
let opts = Object.assign({}, options) | ||
opts._commandArgs = [commandLetter] | ||
opts._commandArgs.push(archive) | ||
opts = setTarget(opts, source) | ||
opts._matchBodyData = matchBodyList | ||
opts._matchEndOfHeaders = matchEndOfHeadersHyphen | ||
opts._matchEndOfBody = matchEndOfBodyHyphen | ||
const stream = new SevenZipStream(opts) | ||
return stream | ||
} | ||
|
||
export function add (archive, source, options) { | ||
return commandStandard('a', archive, source, options) | ||
return new SevenZipStream(opts) | ||
} | ||
|
||
export function remove (archive, source, options) { | ||
return commandStandard('d', archive, source, options) | ||
} | ||
|
||
export function extract (archive, output, cherryPick, options) { | ||
return commandExtract('e', archive, output, cherryPick, options) | ||
} | ||
|
||
export function extractFull (archive, output, cherryPick, options) { | ||
return commandExtract('x', archive, output, cherryPick, options) | ||
} | ||
|
||
export function hash (target, options) { | ||
return commandHash('h', target, options) | ||
} | ||
|
||
export function list (archive, target, options) { | ||
return commandList('l', archive, target, options) | ||
function setTarget (opts, target) { | ||
const isTargetMultiple = (Array.isArray(target)) | ||
if (isTargetMultiple) { | ||
opts._commandArgs = opts._commandArgs.concat(target) | ||
} else if (target) { | ||
opts._commandArgs.push(target) | ||
} | ||
return opts | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters