+ Test
Added a test programm to upload images for characters
This commit is contained in:
Binary file not shown.
+7
-6
@@ -2,14 +2,15 @@
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
"$basedir/node" "$basedir/../color-support/bin.js" "$@"
|
||||
ret=$?
|
||||
exec "$basedir/node" "$basedir/../color-support/bin.js" "$@"
|
||||
else
|
||||
node "$basedir/../color-support/bin.js" "$@"
|
||||
ret=$?
|
||||
exec node "$basedir/../color-support/bin.js" "$@"
|
||||
fi
|
||||
exit $ret
|
||||
|
||||
+15
-5
@@ -1,7 +1,17 @@
|
||||
@IF EXIST "%~dp0\node.exe" (
|
||||
"%~dp0\node.exe" "%~dp0\..\color-support\bin.js" %*
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
@SETLOCAL
|
||||
@SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
node "%~dp0\..\color-support\bin.js" %*
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\color-support\bin.js" %*
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env pwsh
|
||||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
|
||||
|
||||
$exe=""
|
||||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
||||
# Fix case when both the Windows and Linux builds of Node
|
||||
# are installed in the same directory
|
||||
$exe=".exe"
|
||||
}
|
||||
$ret=0
|
||||
if (Test-Path "$basedir/node$exe") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../color-support/bin.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../color-support/bin.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../color-support/bin.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../color-support/bin.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
||||
+7
-6
@@ -2,14 +2,15 @@
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
"$basedir/node" "$basedir/../mime/cli.js" "$@"
|
||||
ret=$?
|
||||
exec "$basedir/node" "$basedir/../mime/cli.js" "$@"
|
||||
else
|
||||
node "$basedir/../mime/cli.js" "$@"
|
||||
ret=$?
|
||||
exec node "$basedir/../mime/cli.js" "$@"
|
||||
fi
|
||||
exit $ret
|
||||
|
||||
+15
-5
@@ -1,7 +1,17 @@
|
||||
@IF EXIST "%~dp0\node.exe" (
|
||||
"%~dp0\node.exe" "%~dp0\..\mime\cli.js" %*
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
@SETLOCAL
|
||||
@SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
node "%~dp0\..\mime\cli.js" %*
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\mime\cli.js" %*
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env pwsh
|
||||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
|
||||
|
||||
$exe=""
|
||||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
||||
# Fix case when both the Windows and Linux builds of Node
|
||||
# are installed in the same directory
|
||||
$exe=".exe"
|
||||
}
|
||||
$ret=0
|
||||
if (Test-Path "$basedir/node$exe") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../mime/cli.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../mime/cli.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../mime/cli.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../mime/cli.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
||||
+7
-6
@@ -2,14 +2,15 @@
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
"$basedir/node" "$basedir/../mkdirp/bin/cmd.js" "$@"
|
||||
ret=$?
|
||||
exec "$basedir/node" "$basedir/../mkdirp/bin/cmd.js" "$@"
|
||||
else
|
||||
node "$basedir/../mkdirp/bin/cmd.js" "$@"
|
||||
ret=$?
|
||||
exec node "$basedir/../mkdirp/bin/cmd.js" "$@"
|
||||
fi
|
||||
exit $ret
|
||||
|
||||
+15
-5
@@ -1,7 +1,17 @@
|
||||
@IF EXIST "%~dp0\node.exe" (
|
||||
"%~dp0\node.exe" "%~dp0\..\mkdirp\bin\cmd.js" %*
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
@SETLOCAL
|
||||
@SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
node "%~dp0\..\mkdirp\bin\cmd.js" %*
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\mkdirp\bin\cmd.js" %*
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env pwsh
|
||||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
|
||||
|
||||
$exe=""
|
||||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
||||
# Fix case when both the Windows and Linux builds of Node
|
||||
# are installed in the same directory
|
||||
$exe=".exe"
|
||||
}
|
||||
$ret=0
|
||||
if (Test-Path "$basedir/node$exe") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../mkdirp/bin/cmd.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../mkdirp/bin/cmd.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../mkdirp/bin/cmd.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../mkdirp/bin/cmd.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
||||
+7
-6
@@ -2,14 +2,15 @@
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
"$basedir/node" "$basedir/../node-gyp/bin/node-gyp.js" "$@"
|
||||
ret=$?
|
||||
exec "$basedir/node" "$basedir/../node-gyp/bin/node-gyp.js" "$@"
|
||||
else
|
||||
node "$basedir/../node-gyp/bin/node-gyp.js" "$@"
|
||||
ret=$?
|
||||
exec node "$basedir/../node-gyp/bin/node-gyp.js" "$@"
|
||||
fi
|
||||
exit $ret
|
||||
|
||||
+15
-5
@@ -1,7 +1,17 @@
|
||||
@IF EXIST "%~dp0\node.exe" (
|
||||
"%~dp0\node.exe" "%~dp0\..\node-gyp\bin\node-gyp.js" %*
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
@SETLOCAL
|
||||
@SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
node "%~dp0\..\node-gyp\bin\node-gyp.js" %*
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\node-gyp\bin\node-gyp.js" %*
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env pwsh
|
||||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
|
||||
|
||||
$exe=""
|
||||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
||||
# Fix case when both the Windows and Linux builds of Node
|
||||
# are installed in the same directory
|
||||
$exe=".exe"
|
||||
}
|
||||
$ret=0
|
||||
if (Test-Path "$basedir/node$exe") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../node-gyp/bin/node-gyp.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../node-gyp/bin/node-gyp.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../node-gyp/bin/node-gyp.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../node-gyp/bin/node-gyp.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
||||
+7
-6
@@ -2,14 +2,15 @@
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
"$basedir/node" "$basedir/../@mapbox/node-pre-gyp/bin/node-pre-gyp" "$@"
|
||||
ret=$?
|
||||
exec "$basedir/node" "$basedir/../@mapbox/node-pre-gyp/bin/node-pre-gyp" "$@"
|
||||
else
|
||||
node "$basedir/../@mapbox/node-pre-gyp/bin/node-pre-gyp" "$@"
|
||||
ret=$?
|
||||
exec node "$basedir/../@mapbox/node-pre-gyp/bin/node-pre-gyp" "$@"
|
||||
fi
|
||||
exit $ret
|
||||
|
||||
+15
-5
@@ -1,7 +1,17 @@
|
||||
@IF EXIST "%~dp0\node.exe" (
|
||||
"%~dp0\node.exe" "%~dp0\..\@mapbox\node-pre-gyp\bin\node-pre-gyp" %*
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
@SETLOCAL
|
||||
@SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
node "%~dp0\..\@mapbox\node-pre-gyp\bin\node-pre-gyp" %*
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\@mapbox\node-pre-gyp\bin\node-pre-gyp" %*
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env pwsh
|
||||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
|
||||
|
||||
$exe=""
|
||||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
||||
# Fix case when both the Windows and Linux builds of Node
|
||||
# are installed in the same directory
|
||||
$exe=".exe"
|
||||
}
|
||||
$ret=0
|
||||
if (Test-Path "$basedir/node$exe") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../@mapbox/node-pre-gyp/bin/node-pre-gyp" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../@mapbox/node-pre-gyp/bin/node-pre-gyp" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../@mapbox/node-pre-gyp/bin/node-pre-gyp" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../@mapbox/node-pre-gyp/bin/node-pre-gyp" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
||||
+7
-6
@@ -2,14 +2,15 @@
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
"$basedir/node" "$basedir/../which/bin/node-which" "$@"
|
||||
ret=$?
|
||||
exec "$basedir/node" "$basedir/../which/bin/node-which" "$@"
|
||||
else
|
||||
node "$basedir/../which/bin/node-which" "$@"
|
||||
ret=$?
|
||||
exec node "$basedir/../which/bin/node-which" "$@"
|
||||
fi
|
||||
exit $ret
|
||||
|
||||
+15
-5
@@ -1,7 +1,17 @@
|
||||
@IF EXIST "%~dp0\node.exe" (
|
||||
"%~dp0\node.exe" "%~dp0\..\which\bin\node-which" %*
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
@SETLOCAL
|
||||
@SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
node "%~dp0\..\which\bin\node-which" %*
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\which\bin\node-which" %*
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env pwsh
|
||||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
|
||||
|
||||
$exe=""
|
||||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
||||
# Fix case when both the Windows and Linux builds of Node
|
||||
# are installed in the same directory
|
||||
$exe=".exe"
|
||||
}
|
||||
$ret=0
|
||||
if (Test-Path "$basedir/node$exe") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../which/bin/node-which" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../which/bin/node-which" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../which/bin/node-which" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../which/bin/node-which" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
||||
+7
-6
@@ -2,14 +2,15 @@
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
"$basedir/node" "$basedir/../nopt/bin/nopt.js" "$@"
|
||||
ret=$?
|
||||
exec "$basedir/node" "$basedir/../nopt/bin/nopt.js" "$@"
|
||||
else
|
||||
node "$basedir/../nopt/bin/nopt.js" "$@"
|
||||
ret=$?
|
||||
exec node "$basedir/../nopt/bin/nopt.js" "$@"
|
||||
fi
|
||||
exit $ret
|
||||
|
||||
+15
-5
@@ -1,7 +1,17 @@
|
||||
@IF EXIST "%~dp0\node.exe" (
|
||||
"%~dp0\node.exe" "%~dp0\..\nopt\bin\nopt.js" %*
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
@SETLOCAL
|
||||
@SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
node "%~dp0\..\nopt\bin\nopt.js" %*
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\nopt\bin\nopt.js" %*
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env pwsh
|
||||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
|
||||
|
||||
$exe=""
|
||||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
||||
# Fix case when both the Windows and Linux builds of Node
|
||||
# are installed in the same directory
|
||||
$exe=".exe"
|
||||
}
|
||||
$ret=0
|
||||
if (Test-Path "$basedir/node$exe") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../nopt/bin/nopt.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../nopt/bin/nopt.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../nopt/bin/nopt.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../nopt/bin/nopt.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
||||
+7
-6
@@ -2,14 +2,15 @@
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
"$basedir/node" "$basedir/../prebuild-install/bin.js" "$@"
|
||||
ret=$?
|
||||
exec "$basedir/node" "$basedir/../prebuild-install/bin.js" "$@"
|
||||
else
|
||||
node "$basedir/../prebuild-install/bin.js" "$@"
|
||||
ret=$?
|
||||
exec node "$basedir/../prebuild-install/bin.js" "$@"
|
||||
fi
|
||||
exit $ret
|
||||
|
||||
+15
-5
@@ -1,7 +1,17 @@
|
||||
@IF EXIST "%~dp0\node.exe" (
|
||||
"%~dp0\node.exe" "%~dp0\..\prebuild-install\bin.js" %*
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
@SETLOCAL
|
||||
@SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
node "%~dp0\..\prebuild-install\bin.js" %*
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\prebuild-install\bin.js" %*
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env pwsh
|
||||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
|
||||
|
||||
$exe=""
|
||||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
||||
# Fix case when both the Windows and Linux builds of Node
|
||||
# are installed in the same directory
|
||||
$exe=".exe"
|
||||
}
|
||||
$ret=0
|
||||
if (Test-Path "$basedir/node$exe") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../prebuild-install/bin.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../prebuild-install/bin.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../prebuild-install/bin.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../prebuild-install/bin.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
||||
+7
-6
@@ -2,14 +2,15 @@
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
"$basedir/node" "$basedir/../rc/cli.js" "$@"
|
||||
ret=$?
|
||||
exec "$basedir/node" "$basedir/../rc/cli.js" "$@"
|
||||
else
|
||||
node "$basedir/../rc/cli.js" "$@"
|
||||
ret=$?
|
||||
exec node "$basedir/../rc/cli.js" "$@"
|
||||
fi
|
||||
exit $ret
|
||||
|
||||
+15
-5
@@ -1,7 +1,17 @@
|
||||
@IF EXIST "%~dp0\node.exe" (
|
||||
"%~dp0\node.exe" "%~dp0\..\rc\cli.js" %*
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
@SETLOCAL
|
||||
@SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
node "%~dp0\..\rc\cli.js" %*
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\rc\cli.js" %*
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env pwsh
|
||||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
|
||||
|
||||
$exe=""
|
||||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
||||
# Fix case when both the Windows and Linux builds of Node
|
||||
# are installed in the same directory
|
||||
$exe=".exe"
|
||||
}
|
||||
$ret=0
|
||||
if (Test-Path "$basedir/node$exe") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../rc/cli.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../rc/cli.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../rc/cli.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../rc/cli.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
||||
+7
-6
@@ -2,14 +2,15 @@
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
"$basedir/node" "$basedir/../rimraf/bin.js" "$@"
|
||||
ret=$?
|
||||
exec "$basedir/node" "$basedir/../rimraf/bin.js" "$@"
|
||||
else
|
||||
node "$basedir/../rimraf/bin.js" "$@"
|
||||
ret=$?
|
||||
exec node "$basedir/../rimraf/bin.js" "$@"
|
||||
fi
|
||||
exit $ret
|
||||
|
||||
+15
-5
@@ -1,7 +1,17 @@
|
||||
@IF EXIST "%~dp0\node.exe" (
|
||||
"%~dp0\node.exe" "%~dp0\..\rimraf\bin.js" %*
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
@SETLOCAL
|
||||
@SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
node "%~dp0\..\rimraf\bin.js" %*
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\rimraf\bin.js" %*
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env pwsh
|
||||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
|
||||
|
||||
$exe=""
|
||||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
||||
# Fix case when both the Windows and Linux builds of Node
|
||||
# are installed in the same directory
|
||||
$exe=".exe"
|
||||
}
|
||||
$ret=0
|
||||
if (Test-Path "$basedir/node$exe") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../rimraf/bin.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../rimraf/bin.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../rimraf/bin.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../rimraf/bin.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
||||
+7
-6
@@ -2,14 +2,15 @@
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
"$basedir/node" "$basedir/../make-dir/node_modules/semver/bin/semver.js" "$@"
|
||||
ret=$?
|
||||
exec "$basedir/node" "$basedir/../semver/bin/semver.js" "$@"
|
||||
else
|
||||
node "$basedir/../make-dir/node_modules/semver/bin/semver.js" "$@"
|
||||
ret=$?
|
||||
exec node "$basedir/../semver/bin/semver.js" "$@"
|
||||
fi
|
||||
exit $ret
|
||||
|
||||
+15
-5
@@ -1,7 +1,17 @@
|
||||
@IF EXIST "%~dp0\node.exe" (
|
||||
"%~dp0\node.exe" "%~dp0\..\make-dir\node_modules\semver\bin\semver.js" %*
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
@SETLOCAL
|
||||
@SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
node "%~dp0\..\make-dir\node_modules\semver\bin\semver.js" %*
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\semver\bin\semver.js" %*
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env pwsh
|
||||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
|
||||
|
||||
$exe=""
|
||||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
||||
# Fix case when both the Windows and Linux builds of Node
|
||||
# are installed in the same directory
|
||||
$exe=".exe"
|
||||
}
|
||||
$ret=0
|
||||
if (Test-Path "$basedir/node$exe") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../semver/bin/semver.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../semver/bin/semver.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../semver/bin/semver.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../semver/bin/semver.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
||||
+2558
File diff suppressed because it is too large
Load Diff
+21
@@ -10,6 +10,7 @@
|
||||
"body-parser@^1.20.3",
|
||||
"cors@^2.8.5",
|
||||
"express@^4.21.2",
|
||||
"multer@^1.4.5-lts.1",
|
||||
"sqlite3@^5.1.7"
|
||||
],
|
||||
"lockfileEntries": {
|
||||
@@ -25,6 +26,7 @@
|
||||
"agentkeepalive@^4.1.3": "https://registry.yarnpkg.com/agentkeepalive/-/agentkeepalive-4.5.0.tgz#2673ad1389b3c418c5a20c5d7364f93ca04be923",
|
||||
"aggregate-error@^3.0.0": "https://registry.yarnpkg.com/aggregate-error/-/aggregate-error-3.1.0.tgz#92670ff50f5359bdb7a3e0d40d0ec30c5737687a",
|
||||
"ansi-regex@^5.0.1": "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304",
|
||||
"append-field@^1.0.0": "https://registry.yarnpkg.com/append-field/-/append-field-1.0.0.tgz#1e3440e915f0b1203d23748e78edd7b9b5b43e56",
|
||||
"aproba@^1.0.3 || ^2.0.0": "https://registry.yarnpkg.com/aproba/-/aproba-2.0.0.tgz#52520b8ae5b569215b354efc0caa3fe1e45a8adc",
|
||||
"are-we-there-yet@^2.0.0": "https://registry.yarnpkg.com/are-we-there-yet/-/are-we-there-yet-2.0.0.tgz#372e0e7bd279d8e94c653aaa1f67200884bf3e1c",
|
||||
"are-we-there-yet@^3.0.0": "https://registry.yarnpkg.com/are-we-there-yet/-/are-we-there-yet-3.0.1.tgz#679df222b278c64f2cdba1175cdc00b0d96164bd",
|
||||
@@ -37,7 +39,9 @@
|
||||
"body-parser@1.20.3": "https://registry.yarnpkg.com/body-parser/-/body-parser-1.20.3.tgz#1953431221c6fb5cd63c4b36d53fab0928e548c6",
|
||||
"body-parser@^1.20.3": "https://registry.yarnpkg.com/body-parser/-/body-parser-1.20.3.tgz#1953431221c6fb5cd63c4b36d53fab0928e548c6",
|
||||
"brace-expansion@^1.1.7": "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd",
|
||||
"buffer-from@^1.0.0": "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.2.tgz#2b146a6fd72e80b4f55d255f35ed59a3a9a41bd5",
|
||||
"buffer@^5.5.0": "https://registry.yarnpkg.com/buffer/-/buffer-5.7.1.tgz#ba62e7c13133053582197160851a8f648e99eed0",
|
||||
"busboy@^1.0.0": "https://registry.yarnpkg.com/busboy/-/busboy-1.6.0.tgz#966ea36a9502e43cdb9146962523b92f531f6893",
|
||||
"bytes@3.1.2": "https://registry.yarnpkg.com/bytes/-/bytes-3.1.2.tgz#8b0beeb98605adf1b128fa4386403c009e0221a5",
|
||||
"cacache@^15.2.0": "https://registry.yarnpkg.com/cacache/-/cacache-15.3.0.tgz#dc85380fb2f556fe3dda4c719bfa0ec875a7f1eb",
|
||||
"call-bind-apply-helpers@^1.0.1": "https://registry.yarnpkg.com/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.1.tgz#32e5892e6361b29b0b545ba6f7763378daca2840",
|
||||
@@ -48,6 +52,7 @@
|
||||
"color-support@^1.1.2": "https://registry.yarnpkg.com/color-support/-/color-support-1.1.3.tgz#93834379a1cc9a0c61f82f52f0d04322251bd5a2",
|
||||
"color-support@^1.1.3": "https://registry.yarnpkg.com/color-support/-/color-support-1.1.3.tgz#93834379a1cc9a0c61f82f52f0d04322251bd5a2",
|
||||
"concat-map@0.0.1": "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b",
|
||||
"concat-stream@^1.5.2": "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.6.2.tgz#904bdf194cd3122fc675c77fc4ac3d4ff0fd1a34",
|
||||
"console-control-strings@^1.0.0": "https://registry.yarnpkg.com/console-control-strings/-/console-control-strings-1.1.0.tgz#3d7cf4464db6446ea644bf4b39507f9851008e8e",
|
||||
"console-control-strings@^1.1.0": "https://registry.yarnpkg.com/console-control-strings/-/console-control-strings-1.1.0.tgz#3d7cf4464db6446ea644bf4b39507f9851008e8e",
|
||||
"content-disposition@0.5.4": "https://registry.yarnpkg.com/content-disposition/-/content-disposition-0.5.4.tgz#8b82b4efac82512a02bb0b1dcec9d2c5e8eb5bfe",
|
||||
@@ -55,6 +60,7 @@
|
||||
"content-type@~1.0.5": "https://registry.yarnpkg.com/content-type/-/content-type-1.0.5.tgz#8b773162656d1d1086784c8f23a54ce6d73d7918",
|
||||
"cookie-signature@1.0.6": "https://registry.yarnpkg.com/cookie-signature/-/cookie-signature-1.0.6.tgz#e303a882b342cc3ee8ca513a79999734dab3ae2c",
|
||||
"cookie@0.7.1": "https://registry.yarnpkg.com/cookie/-/cookie-0.7.1.tgz#2f73c42142d5d5cf71310a74fc4ae61670e5dbc9",
|
||||
"core-util-is@~1.0.0": "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85",
|
||||
"cors@^2.8.5": "https://registry.yarnpkg.com/cors/-/cors-2.8.5.tgz#eac11da51592dd86b9f06f6e7ac293b3df875d29",
|
||||
"debug@2.6.9": "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f",
|
||||
"debug@4": "https://registry.yarnpkg.com/debug/-/debug-4.4.0.tgz#2b3f2aea2ffeb776477460267377dc8710faba8a",
|
||||
@@ -118,11 +124,13 @@
|
||||
"inherits@2.0.4": "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c",
|
||||
"inherits@^2.0.3": "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c",
|
||||
"inherits@^2.0.4": "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c",
|
||||
"inherits@~2.0.3": "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c",
|
||||
"ini@~1.3.0": "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c",
|
||||
"ip-address@^9.0.5": "https://registry.yarnpkg.com/ip-address/-/ip-address-9.0.5.tgz#117a960819b08780c3bd1f14ef3c1cc1d3f3ea5a",
|
||||
"ipaddr.js@1.9.1": "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.9.1.tgz#bff38543eeb8984825079ff3a2a8e6cbd46781b3",
|
||||
"is-fullwidth-code-point@^3.0.0": "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz#f116f8064fe90b3f7844a38997c0b75051269f1d",
|
||||
"is-lambda@^1.0.1": "https://registry.yarnpkg.com/is-lambda/-/is-lambda-1.0.1.tgz#3d9877899e6a53efc0160504cde15f82e6f061d5",
|
||||
"isarray@~1.0.0": "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11",
|
||||
"isexe@^2.0.0": "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10",
|
||||
"jsbn@1.1.0": "https://registry.yarnpkg.com/jsbn/-/jsbn-1.1.0.tgz#b01307cb29b618a1ed26ec79e911f803c4da0040",
|
||||
"lru-cache@^6.0.0": "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94",
|
||||
@@ -140,6 +148,7 @@
|
||||
"minimatch@^3.1.1": "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b",
|
||||
"minimist@^1.2.0": "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c",
|
||||
"minimist@^1.2.3": "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c",
|
||||
"minimist@^1.2.6": "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c",
|
||||
"minipass-collect@^1.0.2": "https://registry.yarnpkg.com/minipass-collect/-/minipass-collect-1.0.2.tgz#22b813bf745dc6edba2576b940022ad6edc8c617",
|
||||
"minipass-fetch@^1.3.2": "https://registry.yarnpkg.com/minipass-fetch/-/minipass-fetch-1.4.1.tgz#d75e0091daac1b0ffd7e9d41629faff7d0c1f1b6",
|
||||
"minipass-flush@^1.0.5": "https://registry.yarnpkg.com/minipass-flush/-/minipass-flush-1.0.5.tgz#82e7135d7e89a50ffe64610a787953c4c4cbb373",
|
||||
@@ -155,12 +164,14 @@
|
||||
"minizlib@^2.1.1": "https://registry.yarnpkg.com/minizlib/-/minizlib-2.1.2.tgz#e90d3466ba209b932451508a11ce3d3632145931",
|
||||
"mkdirp-classic@^0.5.2": "https://registry.yarnpkg.com/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz#fa10c9115cc6d8865be221ba47ee9bed78601113",
|
||||
"mkdirp-classic@^0.5.3": "https://registry.yarnpkg.com/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz#fa10c9115cc6d8865be221ba47ee9bed78601113",
|
||||
"mkdirp@^0.5.4": "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.6.tgz#7def03d2432dcae4ba1d611445c48396062255f6",
|
||||
"mkdirp@^1.0.3": "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e",
|
||||
"mkdirp@^1.0.4": "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e",
|
||||
"ms@2.0.0": "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8",
|
||||
"ms@2.1.3": "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2",
|
||||
"ms@^2.0.0": "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2",
|
||||
"ms@^2.1.3": "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2",
|
||||
"multer@^1.4.5-lts.1": "https://registry.yarnpkg.com/multer/-/multer-1.4.5-lts.1.tgz#803e24ad1984f58edffbc79f56e305aec5cfd1ac",
|
||||
"napi-build-utils@^1.0.1": "https://registry.yarnpkg.com/napi-build-utils/-/napi-build-utils-1.0.2.tgz#b1fddc0b2c46e380a0b7a76f984dd47c41a13806",
|
||||
"negotiator@0.6.3": "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.3.tgz#58e323a72fedc0d6f9cd4d31fe49f51479590ccd",
|
||||
"negotiator@^0.6.2": "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.4.tgz#777948e2452651c570b712dd01c23e262713fff7",
|
||||
@@ -184,6 +195,7 @@
|
||||
"path-is-absolute@^1.0.0": "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f",
|
||||
"path-to-regexp@0.1.12": "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.12.tgz#d5e1a12e478a976d432ef3c58d534b9923164bb7",
|
||||
"prebuild-install@^7.1.1": "https://registry.yarnpkg.com/prebuild-install/-/prebuild-install-7.1.2.tgz#a5fd9986f5a6251fbc47e1e5c65de71e68c0a056",
|
||||
"process-nextick-args@~2.0.0": "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2",
|
||||
"promise-inflight@^1.0.1": "https://registry.yarnpkg.com/promise-inflight/-/promise-inflight-1.0.1.tgz#98472870bf228132fcbdd868129bad12c3c029e3",
|
||||
"promise-retry@^2.0.1": "https://registry.yarnpkg.com/promise-retry/-/promise-retry-2.0.1.tgz#ff747a13620ab57ba688f5fc67855410c370da22",
|
||||
"proxy-addr@~2.0.7": "https://registry.yarnpkg.com/proxy-addr/-/proxy-addr-2.0.7.tgz#f19fe69ceab311eeb94b42e70e8c2070f9ba1025",
|
||||
@@ -192,6 +204,7 @@
|
||||
"range-parser@~1.2.1": "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.1.tgz#3cf37023d199e1c24d1a55b84800c2f3e6468031",
|
||||
"raw-body@2.5.2": "https://registry.yarnpkg.com/raw-body/-/raw-body-2.5.2.tgz#99febd83b90e08975087e8f1f9419a149366b68a",
|
||||
"rc@^1.2.7": "https://registry.yarnpkg.com/rc/-/rc-1.2.8.tgz#cd924bf5200a075b83c188cd6b9e211b7fc0d3ed",
|
||||
"readable-stream@^2.2.2": "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.8.tgz#91125e8042bba1b9887f49345f6277027ce8be9b",
|
||||
"readable-stream@^3.1.1": "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.2.tgz#56a9b36ea965c00c5a93ef31eb111a0f11056967",
|
||||
"readable-stream@^3.4.0": "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.2.tgz#56a9b36ea965c00c5a93ef31eb111a0f11056967",
|
||||
"readable-stream@^3.6.0": "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.2.tgz#56a9b36ea965c00c5a93ef31eb111a0f11056967",
|
||||
@@ -199,6 +212,8 @@
|
||||
"rimraf@^3.0.2": "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.2.tgz#f1a5402ba6220ad52cc1282bac1ae3aa49fd061a",
|
||||
"safe-buffer@5.2.1": "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6",
|
||||
"safe-buffer@^5.0.1": "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6",
|
||||
"safe-buffer@~5.1.0": "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d",
|
||||
"safe-buffer@~5.1.1": "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d",
|
||||
"safe-buffer@~5.2.0": "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6",
|
||||
"safer-buffer@>= 2.1.2 < 3": "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a",
|
||||
"safer-buffer@>= 2.1.2 < 3.0.0": "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a",
|
||||
@@ -224,9 +239,11 @@
|
||||
"ssri@^8.0.0": "https://registry.yarnpkg.com/ssri/-/ssri-8.0.1.tgz#638e4e439e2ffbd2cd289776d5ca457c4f51a2af",
|
||||
"ssri@^8.0.1": "https://registry.yarnpkg.com/ssri/-/ssri-8.0.1.tgz#638e4e439e2ffbd2cd289776d5ca457c4f51a2af",
|
||||
"statuses@2.0.1": "https://registry.yarnpkg.com/statuses/-/statuses-2.0.1.tgz#55cb000ccf1d48728bd23c685a063998cf1a1b63",
|
||||
"streamsearch@^1.1.0": "https://registry.yarnpkg.com/streamsearch/-/streamsearch-1.1.0.tgz#404dd1e2247ca94af554e841a8ef0eaa238da764",
|
||||
"string-width@^1.0.2 || 2 || 3 || 4": "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010",
|
||||
"string-width@^4.2.3": "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010",
|
||||
"string_decoder@^1.1.1": "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e",
|
||||
"string_decoder@~1.1.1": "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8",
|
||||
"strip-ansi@^6.0.1": "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9",
|
||||
"strip-json-comments@~2.0.1": "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a",
|
||||
"tar-fs@^2.0.0": "https://registry.yarnpkg.com/tar-fs/-/tar-fs-2.1.1.tgz#489a15ab85f1f0befabb370b7de4f9eb5cbe8784",
|
||||
@@ -237,12 +254,15 @@
|
||||
"toidentifier@1.0.1": "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.1.tgz#3be34321a88a820ed1bd80dfaa33e479fbb8dd35",
|
||||
"tr46@~0.0.3": "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a",
|
||||
"tunnel-agent@^0.6.0": "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd",
|
||||
"type-is@^1.6.4": "https://registry.yarnpkg.com/type-is/-/type-is-1.6.18.tgz#4e552cd05df09467dcbc4ef739de89f2cf37c131",
|
||||
"type-is@~1.6.18": "https://registry.yarnpkg.com/type-is/-/type-is-1.6.18.tgz#4e552cd05df09467dcbc4ef739de89f2cf37c131",
|
||||
"typedarray@^0.0.6": "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777",
|
||||
"unique-filename@^1.1.1": "https://registry.yarnpkg.com/unique-filename/-/unique-filename-1.1.1.tgz#1d69769369ada0583103a1e6ae87681b56573230",
|
||||
"unique-slug@^2.0.0": "https://registry.yarnpkg.com/unique-slug/-/unique-slug-2.0.2.tgz#baabce91083fc64e945b0f3ad613e264f7cd4e6c",
|
||||
"unpipe@1.0.0": "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec",
|
||||
"unpipe@~1.0.0": "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec",
|
||||
"util-deprecate@^1.0.1": "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf",
|
||||
"util-deprecate@~1.0.1": "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf",
|
||||
"utils-merge@1.0.1": "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713",
|
||||
"vary@^1": "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc",
|
||||
"vary@~1.1.2": "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc",
|
||||
@@ -252,6 +272,7 @@
|
||||
"wide-align@^1.1.2": "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.5.tgz#df1d4c206854369ecf3c9a4898f1b23fbd9d15d3",
|
||||
"wide-align@^1.1.5": "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.5.tgz#df1d4c206854369ecf3c9a4898f1b23fbd9d15d3",
|
||||
"wrappy@1": "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f",
|
||||
"xtend@^4.0.0": "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54",
|
||||
"yallist@^4.0.0": "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"
|
||||
},
|
||||
"files": [],
|
||||
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
#!/bin/sh
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
"$basedir/node" "$basedir/../../../../nopt/bin/nopt.js" "$@"
|
||||
ret=$?
|
||||
else
|
||||
node "$basedir/../../../../nopt/bin/nopt.js" "$@"
|
||||
ret=$?
|
||||
fi
|
||||
exit $ret
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
@IF EXIST "%~dp0\node.exe" (
|
||||
"%~dp0\node.exe" "%~dp0\..\..\..\..\nopt\bin\nopt.js" %*
|
||||
) ELSE (
|
||||
@SETLOCAL
|
||||
@SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
node "%~dp0\..\..\..\..\nopt\bin\nopt.js" %*
|
||||
)
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
#!/bin/sh
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
"$basedir/node" "$basedir/../../../../rimraf/bin.js" "$@"
|
||||
ret=$?
|
||||
else
|
||||
node "$basedir/../../../../rimraf/bin.js" "$@"
|
||||
ret=$?
|
||||
fi
|
||||
exit $ret
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
@IF EXIST "%~dp0\node.exe" (
|
||||
"%~dp0\node.exe" "%~dp0\..\..\..\..\rimraf\bin.js" %*
|
||||
) ELSE (
|
||||
@SETLOCAL
|
||||
@SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
node "%~dp0\..\..\..\..\rimraf\bin.js" %*
|
||||
)
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
#!/bin/sh
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
"$basedir/node" "$basedir/../../../../semver/bin/semver.js" "$@"
|
||||
ret=$?
|
||||
else
|
||||
node "$basedir/../../../../semver/bin/semver.js" "$@"
|
||||
ret=$?
|
||||
fi
|
||||
exit $ret
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
@IF EXIST "%~dp0\node.exe" (
|
||||
"%~dp0\node.exe" "%~dp0\..\..\..\..\semver\bin\semver.js" %*
|
||||
) ELSE (
|
||||
@SETLOCAL
|
||||
@SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
node "%~dp0\..\..\..\..\semver\bin\semver.js" %*
|
||||
)
|
||||
+1
@@ -0,0 +1 @@
|
||||
node_modules/
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Linus Unnebäck
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
# `append-field`
|
||||
|
||||
A [W3C HTML JSON forms spec](http://www.w3.org/TR/html-json-forms/) compliant
|
||||
field appender (for lack of a better name). Useful for people implementing
|
||||
`application/x-www-form-urlencoded` and `multipart/form-data` parsers.
|
||||
|
||||
It works best on objects created with `Object.create(null)`. Otherwise it might
|
||||
conflict with variables from the prototype (e.g. `hasOwnProperty`).
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install --save append-field
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```javascript
|
||||
var appendField = require('append-field')
|
||||
var obj = Object.create(null)
|
||||
|
||||
appendField(obj, 'pets[0][species]', 'Dahut')
|
||||
appendField(obj, 'pets[0][name]', 'Hypatia')
|
||||
appendField(obj, 'pets[1][species]', 'Felis Stultus')
|
||||
appendField(obj, 'pets[1][name]', 'Billie')
|
||||
|
||||
console.log(obj)
|
||||
```
|
||||
|
||||
```text
|
||||
{ pets:
|
||||
[ { species: 'Dahut', name: 'Hypatia' },
|
||||
{ species: 'Felis Stultus', name: 'Billie' } ] }
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### `appendField(store, key, value)`
|
||||
|
||||
Adds the field named `key` with the value `value` to the object `store`.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
var parsePath = require('./lib/parse-path')
|
||||
var setValue = require('./lib/set-value')
|
||||
|
||||
function appendField (store, key, value) {
|
||||
var steps = parsePath(key)
|
||||
|
||||
steps.reduce(function (context, step) {
|
||||
return setValue(context, step, context[step.key], value)
|
||||
}, store)
|
||||
}
|
||||
|
||||
module.exports = appendField
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
var reFirstKey = /^[^\[]*/
|
||||
var reDigitPath = /^\[(\d+)\]/
|
||||
var reNormalPath = /^\[([^\]]+)\]/
|
||||
|
||||
function parsePath (key) {
|
||||
function failure () {
|
||||
return [{ type: 'object', key: key, last: true }]
|
||||
}
|
||||
|
||||
var firstKey = reFirstKey.exec(key)[0]
|
||||
if (!firstKey) return failure()
|
||||
|
||||
var len = key.length
|
||||
var pos = firstKey.length
|
||||
var tail = { type: 'object', key: firstKey }
|
||||
var steps = [tail]
|
||||
|
||||
while (pos < len) {
|
||||
var m
|
||||
|
||||
if (key[pos] === '[' && key[pos + 1] === ']') {
|
||||
pos += 2
|
||||
tail.append = true
|
||||
if (pos !== len) return failure()
|
||||
continue
|
||||
}
|
||||
|
||||
m = reDigitPath.exec(key.substring(pos))
|
||||
if (m !== null) {
|
||||
pos += m[0].length
|
||||
tail.nextType = 'array'
|
||||
tail = { type: 'array', key: parseInt(m[1], 10) }
|
||||
steps.push(tail)
|
||||
continue
|
||||
}
|
||||
|
||||
m = reNormalPath.exec(key.substring(pos))
|
||||
if (m !== null) {
|
||||
pos += m[0].length
|
||||
tail.nextType = 'object'
|
||||
tail = { type: 'object', key: m[1] }
|
||||
steps.push(tail)
|
||||
continue
|
||||
}
|
||||
|
||||
return failure()
|
||||
}
|
||||
|
||||
tail.last = true
|
||||
return steps
|
||||
}
|
||||
|
||||
module.exports = parsePath
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
function valueType (value) {
|
||||
if (value === undefined) return 'undefined'
|
||||
if (Array.isArray(value)) return 'array'
|
||||
if (typeof value === 'object') return 'object'
|
||||
return 'scalar'
|
||||
}
|
||||
|
||||
function setLastValue (context, step, currentValue, entryValue) {
|
||||
switch (valueType(currentValue)) {
|
||||
case 'undefined':
|
||||
if (step.append) {
|
||||
context[step.key] = [entryValue]
|
||||
} else {
|
||||
context[step.key] = entryValue
|
||||
}
|
||||
break
|
||||
case 'array':
|
||||
context[step.key].push(entryValue)
|
||||
break
|
||||
case 'object':
|
||||
return setLastValue(currentValue, { type: 'object', key: '', last: true }, currentValue[''], entryValue)
|
||||
case 'scalar':
|
||||
context[step.key] = [context[step.key], entryValue]
|
||||
break
|
||||
}
|
||||
|
||||
return context
|
||||
}
|
||||
|
||||
function setValue (context, step, currentValue, entryValue) {
|
||||
if (step.last) return setLastValue(context, step, currentValue, entryValue)
|
||||
|
||||
var obj
|
||||
switch (valueType(currentValue)) {
|
||||
case 'undefined':
|
||||
if (step.nextType === 'array') {
|
||||
context[step.key] = []
|
||||
} else {
|
||||
context[step.key] = Object.create(null)
|
||||
}
|
||||
return context[step.key]
|
||||
case 'object':
|
||||
return context[step.key]
|
||||
case 'array':
|
||||
if (step.nextType === 'array') {
|
||||
return currentValue
|
||||
}
|
||||
|
||||
obj = Object.create(null)
|
||||
context[step.key] = obj
|
||||
currentValue.forEach(function (item, i) {
|
||||
if (item !== undefined) obj['' + i] = item
|
||||
})
|
||||
|
||||
return obj
|
||||
case 'scalar':
|
||||
obj = Object.create(null)
|
||||
obj[''] = currentValue
|
||||
context[step.key] = obj
|
||||
return obj
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = setValue
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "append-field",
|
||||
"version": "1.0.0",
|
||||
"license": "MIT",
|
||||
"author": "Linus Unnebäck <linus@folkdatorn.se>",
|
||||
"main": "index.js",
|
||||
"devDependencies": {
|
||||
"mocha": "^2.2.4",
|
||||
"standard": "^6.0.5",
|
||||
"testdata-w3c-json-form": "^0.2.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "standard && mocha"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "http://github.com/LinusU/node-append-field.git"
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/* eslint-env mocha */
|
||||
|
||||
var assert = require('assert')
|
||||
var appendField = require('../')
|
||||
var testData = require('testdata-w3c-json-form')
|
||||
|
||||
describe('Append Field', function () {
|
||||
for (var test of testData) {
|
||||
it('handles ' + test.name, function () {
|
||||
var store = Object.create(null)
|
||||
|
||||
for (var field of test.fields) {
|
||||
appendField(store, field.key, field.value)
|
||||
}
|
||||
|
||||
assert.deepEqual(store, test.expected)
|
||||
})
|
||||
}
|
||||
})
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2016, 2018 Linus Unnebäck
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/* eslint-disable node/no-deprecated-api */
|
||||
|
||||
var toString = Object.prototype.toString
|
||||
|
||||
var isModern = (
|
||||
typeof Buffer !== 'undefined' &&
|
||||
typeof Buffer.alloc === 'function' &&
|
||||
typeof Buffer.allocUnsafe === 'function' &&
|
||||
typeof Buffer.from === 'function'
|
||||
)
|
||||
|
||||
function isArrayBuffer (input) {
|
||||
return toString.call(input).slice(8, -1) === 'ArrayBuffer'
|
||||
}
|
||||
|
||||
function fromArrayBuffer (obj, byteOffset, length) {
|
||||
byteOffset >>>= 0
|
||||
|
||||
var maxLength = obj.byteLength - byteOffset
|
||||
|
||||
if (maxLength < 0) {
|
||||
throw new RangeError("'offset' is out of bounds")
|
||||
}
|
||||
|
||||
if (length === undefined) {
|
||||
length = maxLength
|
||||
} else {
|
||||
length >>>= 0
|
||||
|
||||
if (length > maxLength) {
|
||||
throw new RangeError("'length' is out of bounds")
|
||||
}
|
||||
}
|
||||
|
||||
return isModern
|
||||
? Buffer.from(obj.slice(byteOffset, byteOffset + length))
|
||||
: new Buffer(new Uint8Array(obj.slice(byteOffset, byteOffset + length)))
|
||||
}
|
||||
|
||||
function fromString (string, encoding) {
|
||||
if (typeof encoding !== 'string' || encoding === '') {
|
||||
encoding = 'utf8'
|
||||
}
|
||||
|
||||
if (!Buffer.isEncoding(encoding)) {
|
||||
throw new TypeError('"encoding" must be a valid string encoding')
|
||||
}
|
||||
|
||||
return isModern
|
||||
? Buffer.from(string, encoding)
|
||||
: new Buffer(string, encoding)
|
||||
}
|
||||
|
||||
function bufferFrom (value, encodingOrOffset, length) {
|
||||
if (typeof value === 'number') {
|
||||
throw new TypeError('"value" argument must not be a number')
|
||||
}
|
||||
|
||||
if (isArrayBuffer(value)) {
|
||||
return fromArrayBuffer(value, encodingOrOffset, length)
|
||||
}
|
||||
|
||||
if (typeof value === 'string') {
|
||||
return fromString(value, encodingOrOffset)
|
||||
}
|
||||
|
||||
return isModern
|
||||
? Buffer.from(value)
|
||||
: new Buffer(value)
|
||||
}
|
||||
|
||||
module.exports = bufferFrom
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "buffer-from",
|
||||
"version": "1.1.2",
|
||||
"license": "MIT",
|
||||
"repository": "LinusU/buffer-from",
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "standard && node test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"standard": "^12.0.1"
|
||||
},
|
||||
"keywords": [
|
||||
"buffer",
|
||||
"buffer from"
|
||||
]
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
# Buffer From
|
||||
|
||||
A [ponyfill](https://ponyfill.com) for `Buffer.from`, uses native implementation if available.
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install --save buffer-from
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const bufferFrom = require('buffer-from')
|
||||
|
||||
console.log(bufferFrom([1, 2, 3, 4]))
|
||||
//=> <Buffer 01 02 03 04>
|
||||
|
||||
const arr = new Uint8Array([1, 2, 3, 4])
|
||||
console.log(bufferFrom(arr.buffer, 1, 2))
|
||||
//=> <Buffer 02 03>
|
||||
|
||||
console.log(bufferFrom('test', 'utf8'))
|
||||
//=> <Buffer 74 65 73 74>
|
||||
|
||||
const buf = bufferFrom('test')
|
||||
console.log(bufferFrom(buf))
|
||||
//=> <Buffer 74 65 73 74>
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### bufferFrom(array)
|
||||
|
||||
- `array` <Array>
|
||||
|
||||
Allocates a new `Buffer` using an `array` of octets.
|
||||
|
||||
### bufferFrom(arrayBuffer[, byteOffset[, length]])
|
||||
|
||||
- `arrayBuffer` <ArrayBuffer> The `.buffer` property of a TypedArray or ArrayBuffer
|
||||
- `byteOffset` <Integer> Where to start copying from `arrayBuffer`. **Default:** `0`
|
||||
- `length` <Integer> How many bytes to copy from `arrayBuffer`. **Default:** `arrayBuffer.length - byteOffset`
|
||||
|
||||
When passed a reference to the `.buffer` property of a TypedArray instance, the
|
||||
newly created `Buffer` will share the same allocated memory as the TypedArray.
|
||||
|
||||
The optional `byteOffset` and `length` arguments specify a memory range within
|
||||
the `arrayBuffer` that will be shared by the `Buffer`.
|
||||
|
||||
### bufferFrom(buffer)
|
||||
|
||||
- `buffer` <Buffer> An existing `Buffer` to copy data from
|
||||
|
||||
Copies the passed `buffer` data onto a new `Buffer` instance.
|
||||
|
||||
### bufferFrom(string[, encoding])
|
||||
|
||||
- `string` <String> A string to encode.
|
||||
- `encoding` <String> The encoding of `string`. **Default:** `'utf8'`
|
||||
|
||||
Creates a new `Buffer` containing the given JavaScript string `string`. If
|
||||
provided, the `encoding` parameter identifies the character encoding of
|
||||
`string`.
|
||||
|
||||
## See also
|
||||
|
||||
- [buffer-alloc](https://github.com/LinusU/buffer-alloc) A ponyfill for `Buffer.alloc`
|
||||
- [buffer-alloc-unsafe](https://github.com/LinusU/buffer-alloc-unsafe) A ponyfill for `Buffer.allocUnsafe`
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
extends: '@mscdex/eslint-config',
|
||||
};
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
tests-linux:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
node-version: [10.16.0, 10.x, 12.x, 14.x, 16.x]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- name: Install module
|
||||
run: npm install
|
||||
- name: Run tests
|
||||
run: npm test
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
name: lint
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches: [ master ]
|
||||
|
||||
env:
|
||||
NODE_VERSION: 16.x
|
||||
|
||||
jobs:
|
||||
lint-js:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js ${{ env.NODE_VERSION }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
- name: Install ESLint + ESLint configs/plugins
|
||||
run: npm install --only=dev
|
||||
- name: Lint files
|
||||
run: npm run lint
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
Copyright Brian White. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to
|
||||
deal in the Software without restriction, including without limitation the
|
||||
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
IN THE SOFTWARE.
|
||||
+191
@@ -0,0 +1,191 @@
|
||||
# Description
|
||||
|
||||
A node.js module for parsing incoming HTML form data.
|
||||
|
||||
Changes (breaking or otherwise) in v1.0.0 can be found [here](https://github.com/mscdex/busboy/issues/266).
|
||||
|
||||
# Requirements
|
||||
|
||||
* [node.js](http://nodejs.org/) -- v10.16.0 or newer
|
||||
|
||||
|
||||
# Install
|
||||
|
||||
npm install busboy
|
||||
|
||||
|
||||
# Examples
|
||||
|
||||
* Parsing (multipart) with default options:
|
||||
|
||||
```js
|
||||
const http = require('http');
|
||||
|
||||
const busboy = require('busboy');
|
||||
|
||||
http.createServer((req, res) => {
|
||||
if (req.method === 'POST') {
|
||||
console.log('POST request');
|
||||
const bb = busboy({ headers: req.headers });
|
||||
bb.on('file', (name, file, info) => {
|
||||
const { filename, encoding, mimeType } = info;
|
||||
console.log(
|
||||
`File [${name}]: filename: %j, encoding: %j, mimeType: %j`,
|
||||
filename,
|
||||
encoding,
|
||||
mimeType
|
||||
);
|
||||
file.on('data', (data) => {
|
||||
console.log(`File [${name}] got ${data.length} bytes`);
|
||||
}).on('close', () => {
|
||||
console.log(`File [${name}] done`);
|
||||
});
|
||||
});
|
||||
bb.on('field', (name, val, info) => {
|
||||
console.log(`Field [${name}]: value: %j`, val);
|
||||
});
|
||||
bb.on('close', () => {
|
||||
console.log('Done parsing form!');
|
||||
res.writeHead(303, { Connection: 'close', Location: '/' });
|
||||
res.end();
|
||||
});
|
||||
req.pipe(bb);
|
||||
} else if (req.method === 'GET') {
|
||||
res.writeHead(200, { Connection: 'close' });
|
||||
res.end(`
|
||||
<html>
|
||||
<head></head>
|
||||
<body>
|
||||
<form method="POST" enctype="multipart/form-data">
|
||||
<input type="file" name="filefield"><br />
|
||||
<input type="text" name="textfield"><br />
|
||||
<input type="submit">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
`);
|
||||
}
|
||||
}).listen(8000, () => {
|
||||
console.log('Listening for requests');
|
||||
});
|
||||
|
||||
// Example output:
|
||||
//
|
||||
// Listening for requests
|
||||
// < ... form submitted ... >
|
||||
// POST request
|
||||
// File [filefield]: filename: "logo.jpg", encoding: "binary", mime: "image/jpeg"
|
||||
// File [filefield] got 11912 bytes
|
||||
// Field [textfield]: value: "testing! :-)"
|
||||
// File [filefield] done
|
||||
// Done parsing form!
|
||||
```
|
||||
|
||||
* Save all incoming files to disk:
|
||||
|
||||
```js
|
||||
const { randomFillSync } = require('crypto');
|
||||
const fs = require('fs');
|
||||
const http = require('http');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
|
||||
const busboy = require('busboy');
|
||||
|
||||
const random = (() => {
|
||||
const buf = Buffer.alloc(16);
|
||||
return () => randomFillSync(buf).toString('hex');
|
||||
})();
|
||||
|
||||
http.createServer((req, res) => {
|
||||
if (req.method === 'POST') {
|
||||
const bb = busboy({ headers: req.headers });
|
||||
bb.on('file', (name, file, info) => {
|
||||
const saveTo = path.join(os.tmpdir(), `busboy-upload-${random()}`);
|
||||
file.pipe(fs.createWriteStream(saveTo));
|
||||
});
|
||||
bb.on('close', () => {
|
||||
res.writeHead(200, { 'Connection': 'close' });
|
||||
res.end(`That's all folks!`);
|
||||
});
|
||||
req.pipe(bb);
|
||||
return;
|
||||
}
|
||||
res.writeHead(404);
|
||||
res.end();
|
||||
}).listen(8000, () => {
|
||||
console.log('Listening for requests');
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
# API
|
||||
|
||||
## Exports
|
||||
|
||||
`busboy` exports a single function:
|
||||
|
||||
**( _function_ )**(< _object_ >config) - Creates and returns a new _Writable_ form parser stream.
|
||||
|
||||
* Valid `config` properties:
|
||||
|
||||
* **headers** - _object_ - These are the HTTP headers of the incoming request, which are used by individual parsers.
|
||||
|
||||
* **highWaterMark** - _integer_ - highWaterMark to use for the parser stream. **Default:** node's _stream.Writable_ default.
|
||||
|
||||
* **fileHwm** - _integer_ - highWaterMark to use for individual file streams. **Default:** node's _stream.Readable_ default.
|
||||
|
||||
* **defCharset** - _string_ - Default character set to use when one isn't defined. **Default:** `'utf8'`.
|
||||
|
||||
* **defParamCharset** - _string_ - For multipart forms, the default character set to use for values of part header parameters (e.g. filename) that are not extended parameters (that contain an explicit charset). **Default:** `'latin1'`.
|
||||
|
||||
* **preservePath** - _boolean_ - If paths in filenames from file parts in a `'multipart/form-data'` request shall be preserved. **Default:** `false`.
|
||||
|
||||
* **limits** - _object_ - Various limits on incoming data. Valid properties are:
|
||||
|
||||
* **fieldNameSize** - _integer_ - Max field name size (in bytes). **Default:** `100`.
|
||||
|
||||
* **fieldSize** - _integer_ - Max field value size (in bytes). **Default:** `1048576` (1MB).
|
||||
|
||||
* **fields** - _integer_ - Max number of non-file fields. **Default:** `Infinity`.
|
||||
|
||||
* **fileSize** - _integer_ - For multipart forms, the max file size (in bytes). **Default:** `Infinity`.
|
||||
|
||||
* **files** - _integer_ - For multipart forms, the max number of file fields. **Default:** `Infinity`.
|
||||
|
||||
* **parts** - _integer_ - For multipart forms, the max number of parts (fields + files). **Default:** `Infinity`.
|
||||
|
||||
* **headerPairs** - _integer_ - For multipart forms, the max number of header key-value pairs to parse. **Default:** `2000` (same as node's http module).
|
||||
|
||||
This function can throw exceptions if there is something wrong with the values in `config`. For example, if the Content-Type in `headers` is missing entirely, is not a supported type, or is missing the boundary for `'multipart/form-data'` requests.
|
||||
|
||||
## (Special) Parser stream events
|
||||
|
||||
* **file**(< _string_ >name, < _Readable_ >stream, < _object_ >info) - Emitted for each new file found. `name` contains the form field name. `stream` is a _Readable_ stream containing the file's data. No transformations/conversions (e.g. base64 to raw binary) are done on the file's data. `info` contains the following properties:
|
||||
|
||||
* `filename` - _string_ - If supplied, this contains the file's filename. **WARNING:** You should almost _never_ use this value as-is (especially if you are using `preservePath: true` in your `config`) as it could contain malicious input. You are better off generating your own (safe) filenames, or at the very least using a hash of the filename.
|
||||
|
||||
* `encoding` - _string_ - The file's `'Content-Transfer-Encoding'` value.
|
||||
|
||||
* `mimeType` - _string_ - The file's `'Content-Type'` value.
|
||||
|
||||
**Note:** If you listen for this event, you should always consume the `stream` whether you care about its contents or not (you can simply do `stream.resume();` if you want to discard/skip the contents), otherwise the `'finish'`/`'close'` event will never fire on the busboy parser stream.
|
||||
However, if you aren't accepting files, you can either simply not listen for the `'file'` event at all or set `limits.files` to `0`, and any/all files will be automatically skipped (these skipped files will still count towards any configured `limits.files` and `limits.parts` limits though).
|
||||
|
||||
**Note:** If a configured `limits.fileSize` limit was reached for a file, `stream` will both have a boolean property `truncated` set to `true` (best checked at the end of the stream) and emit a `'limit'` event to notify you when this happens.
|
||||
|
||||
* **field**(< _string_ >name, < _string_ >value, < _object_ >info) - Emitted for each new non-file field found. `name` contains the form field name. `value` contains the string value of the field. `info` contains the following properties:
|
||||
|
||||
* `nameTruncated` - _boolean_ - Whether `name` was truncated or not (due to a configured `limits.fieldNameSize` limit)
|
||||
|
||||
* `valueTruncated` - _boolean_ - Whether `value` was truncated or not (due to a configured `limits.fieldSize` limit)
|
||||
|
||||
* `encoding` - _string_ - The field's `'Content-Transfer-Encoding'` value.
|
||||
|
||||
* `mimeType` - _string_ - The field's `'Content-Type'` value.
|
||||
|
||||
* **partsLimit**() - Emitted when the configured `limits.parts` limit has been reached. No more `'file'` or `'field'` events will be emitted.
|
||||
|
||||
* **filesLimit**() - Emitted when the configured `limits.files` limit has been reached. No more `'file'` events will be emitted.
|
||||
|
||||
* **fieldsLimit**() - Emitted when the configured `limits.fields` limit has been reached. No more `'field'` events will be emitted.
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
'use strict';
|
||||
|
||||
function createMultipartBuffers(boundary, sizes) {
|
||||
const bufs = [];
|
||||
for (let i = 0; i < sizes.length; ++i) {
|
||||
const mb = sizes[i] * 1024 * 1024;
|
||||
bufs.push(Buffer.from([
|
||||
`--${boundary}`,
|
||||
`content-disposition: form-data; name="field${i + 1}"`,
|
||||
'',
|
||||
'0'.repeat(mb),
|
||||
'',
|
||||
].join('\r\n')));
|
||||
}
|
||||
bufs.push(Buffer.from([
|
||||
`--${boundary}--`,
|
||||
'',
|
||||
].join('\r\n')));
|
||||
return bufs;
|
||||
}
|
||||
|
||||
const boundary = '-----------------------------168072824752491622650073';
|
||||
const buffers = createMultipartBuffers(boundary, [
|
||||
10,
|
||||
10,
|
||||
10,
|
||||
20,
|
||||
50,
|
||||
]);
|
||||
const calls = {
|
||||
partBegin: 0,
|
||||
headerField: 0,
|
||||
headerValue: 0,
|
||||
headerEnd: 0,
|
||||
headersEnd: 0,
|
||||
partData: 0,
|
||||
partEnd: 0,
|
||||
end: 0,
|
||||
};
|
||||
|
||||
const moduleName = process.argv[2];
|
||||
switch (moduleName) {
|
||||
case 'busboy': {
|
||||
const busboy = require('busboy');
|
||||
|
||||
const parser = busboy({
|
||||
limits: {
|
||||
fieldSizeLimit: Infinity,
|
||||
},
|
||||
headers: {
|
||||
'content-type': `multipart/form-data; boundary=${boundary}`,
|
||||
},
|
||||
});
|
||||
parser.on('field', (name, val, info) => {
|
||||
++calls.partBegin;
|
||||
++calls.partData;
|
||||
++calls.partEnd;
|
||||
}).on('close', () => {
|
||||
++calls.end;
|
||||
console.timeEnd(moduleName);
|
||||
});
|
||||
|
||||
console.time(moduleName);
|
||||
for (const buf of buffers)
|
||||
parser.write(buf);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'formidable': {
|
||||
const { MultipartParser } = require('formidable');
|
||||
|
||||
const parser = new MultipartParser();
|
||||
parser.initWithBoundary(boundary);
|
||||
parser.on('data', ({ name }) => {
|
||||
++calls[name];
|
||||
if (name === 'end')
|
||||
console.timeEnd(moduleName);
|
||||
});
|
||||
|
||||
console.time(moduleName);
|
||||
for (const buf of buffers)
|
||||
parser.write(buf);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 'multiparty': {
|
||||
const { Readable } = require('stream');
|
||||
|
||||
const { Form } = require('multiparty');
|
||||
|
||||
const form = new Form({
|
||||
maxFieldsSize: Infinity,
|
||||
maxFields: Infinity,
|
||||
maxFilesSize: Infinity,
|
||||
autoFields: false,
|
||||
autoFiles: false,
|
||||
});
|
||||
|
||||
const req = new Readable({ read: () => {} });
|
||||
req.headers = {
|
||||
'content-type': `multipart/form-data; boundary=${boundary}`,
|
||||
};
|
||||
|
||||
function hijack(name, fn) {
|
||||
const oldFn = form[name];
|
||||
form[name] = function() {
|
||||
fn();
|
||||
return oldFn.apply(this, arguments);
|
||||
};
|
||||
}
|
||||
|
||||
hijack('onParseHeaderField', () => {
|
||||
++calls.headerField;
|
||||
});
|
||||
hijack('onParseHeaderValue', () => {
|
||||
++calls.headerValue;
|
||||
});
|
||||
hijack('onParsePartBegin', () => {
|
||||
++calls.partBegin;
|
||||
});
|
||||
hijack('onParsePartData', () => {
|
||||
++calls.partData;
|
||||
});
|
||||
hijack('onParsePartEnd', () => {
|
||||
++calls.partEnd;
|
||||
});
|
||||
|
||||
form.on('close', () => {
|
||||
++calls.end;
|
||||
console.timeEnd(moduleName);
|
||||
}).on('part', (p) => p.resume());
|
||||
|
||||
console.time(moduleName);
|
||||
form.parse(req);
|
||||
for (const buf of buffers)
|
||||
req.push(buf);
|
||||
req.push(null);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
if (moduleName === undefined)
|
||||
console.error('Missing parser module name');
|
||||
else
|
||||
console.error(`Invalid parser module name: ${moduleName}`);
|
||||
process.exit(1);
|
||||
}
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
'use strict';
|
||||
|
||||
function createMultipartBuffers(boundary, sizes) {
|
||||
const bufs = [];
|
||||
for (let i = 0; i < sizes.length; ++i) {
|
||||
const mb = sizes[i] * 1024 * 1024;
|
||||
bufs.push(Buffer.from([
|
||||
`--${boundary}`,
|
||||
`content-disposition: form-data; name="field${i + 1}"`,
|
||||
'',
|
||||
'0'.repeat(mb),
|
||||
'',
|
||||
].join('\r\n')));
|
||||
}
|
||||
bufs.push(Buffer.from([
|
||||
`--${boundary}--`,
|
||||
'',
|
||||
].join('\r\n')));
|
||||
return bufs;
|
||||
}
|
||||
|
||||
const boundary = '-----------------------------168072824752491622650073';
|
||||
const buffers = createMultipartBuffers(boundary, (new Array(100)).fill(1));
|
||||
const calls = {
|
||||
partBegin: 0,
|
||||
headerField: 0,
|
||||
headerValue: 0,
|
||||
headerEnd: 0,
|
||||
headersEnd: 0,
|
||||
partData: 0,
|
||||
partEnd: 0,
|
||||
end: 0,
|
||||
};
|
||||
|
||||
const moduleName = process.argv[2];
|
||||
switch (moduleName) {
|
||||
case 'busboy': {
|
||||
const busboy = require('busboy');
|
||||
|
||||
const parser = busboy({
|
||||
limits: {
|
||||
fieldSizeLimit: Infinity,
|
||||
},
|
||||
headers: {
|
||||
'content-type': `multipart/form-data; boundary=${boundary}`,
|
||||
},
|
||||
});
|
||||
parser.on('field', (name, val, info) => {
|
||||
++calls.partBegin;
|
||||
++calls.partData;
|
||||
++calls.partEnd;
|
||||
}).on('close', () => {
|
||||
++calls.end;
|
||||
console.timeEnd(moduleName);
|
||||
});
|
||||
|
||||
console.time(moduleName);
|
||||
for (const buf of buffers)
|
||||
parser.write(buf);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'formidable': {
|
||||
const { MultipartParser } = require('formidable');
|
||||
|
||||
const parser = new MultipartParser();
|
||||
parser.initWithBoundary(boundary);
|
||||
parser.on('data', ({ name }) => {
|
||||
++calls[name];
|
||||
if (name === 'end')
|
||||
console.timeEnd(moduleName);
|
||||
});
|
||||
|
||||
console.time(moduleName);
|
||||
for (const buf of buffers)
|
||||
parser.write(buf);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 'multiparty': {
|
||||
const { Readable } = require('stream');
|
||||
|
||||
const { Form } = require('multiparty');
|
||||
|
||||
const form = new Form({
|
||||
maxFieldsSize: Infinity,
|
||||
maxFields: Infinity,
|
||||
maxFilesSize: Infinity,
|
||||
autoFields: false,
|
||||
autoFiles: false,
|
||||
});
|
||||
|
||||
const req = new Readable({ read: () => {} });
|
||||
req.headers = {
|
||||
'content-type': `multipart/form-data; boundary=${boundary}`,
|
||||
};
|
||||
|
||||
function hijack(name, fn) {
|
||||
const oldFn = form[name];
|
||||
form[name] = function() {
|
||||
fn();
|
||||
return oldFn.apply(this, arguments);
|
||||
};
|
||||
}
|
||||
|
||||
hijack('onParseHeaderField', () => {
|
||||
++calls.headerField;
|
||||
});
|
||||
hijack('onParseHeaderValue', () => {
|
||||
++calls.headerValue;
|
||||
});
|
||||
hijack('onParsePartBegin', () => {
|
||||
++calls.partBegin;
|
||||
});
|
||||
hijack('onParsePartData', () => {
|
||||
++calls.partData;
|
||||
});
|
||||
hijack('onParsePartEnd', () => {
|
||||
++calls.partEnd;
|
||||
});
|
||||
|
||||
form.on('close', () => {
|
||||
++calls.end;
|
||||
console.timeEnd(moduleName);
|
||||
}).on('part', (p) => p.resume());
|
||||
|
||||
console.time(moduleName);
|
||||
form.parse(req);
|
||||
for (const buf of buffers)
|
||||
req.push(buf);
|
||||
req.push(null);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
if (moduleName === undefined)
|
||||
console.error('Missing parser module name');
|
||||
else
|
||||
console.error(`Invalid parser module name: ${moduleName}`);
|
||||
process.exit(1);
|
||||
}
|
||||
+154
@@ -0,0 +1,154 @@
|
||||
'use strict';
|
||||
|
||||
function createMultipartBuffers(boundary, sizes) {
|
||||
const bufs = [];
|
||||
for (let i = 0; i < sizes.length; ++i) {
|
||||
const mb = sizes[i] * 1024 * 1024;
|
||||
bufs.push(Buffer.from([
|
||||
`--${boundary}`,
|
||||
`content-disposition: form-data; name="file${i + 1}"; `
|
||||
+ `filename="random${i + 1}.bin"`,
|
||||
'content-type: application/octet-stream',
|
||||
'',
|
||||
'0'.repeat(mb),
|
||||
'',
|
||||
].join('\r\n')));
|
||||
}
|
||||
bufs.push(Buffer.from([
|
||||
`--${boundary}--`,
|
||||
'',
|
||||
].join('\r\n')));
|
||||
return bufs;
|
||||
}
|
||||
|
||||
const boundary = '-----------------------------168072824752491622650073';
|
||||
const buffers = createMultipartBuffers(boundary, [
|
||||
10,
|
||||
10,
|
||||
10,
|
||||
20,
|
||||
50,
|
||||
]);
|
||||
const calls = {
|
||||
partBegin: 0,
|
||||
headerField: 0,
|
||||
headerValue: 0,
|
||||
headerEnd: 0,
|
||||
headersEnd: 0,
|
||||
partData: 0,
|
||||
partEnd: 0,
|
||||
end: 0,
|
||||
};
|
||||
|
||||
const moduleName = process.argv[2];
|
||||
switch (moduleName) {
|
||||
case 'busboy': {
|
||||
const busboy = require('busboy');
|
||||
|
||||
const parser = busboy({
|
||||
limits: {
|
||||
fieldSizeLimit: Infinity,
|
||||
},
|
||||
headers: {
|
||||
'content-type': `multipart/form-data; boundary=${boundary}`,
|
||||
},
|
||||
});
|
||||
parser.on('file', (name, stream, info) => {
|
||||
++calls.partBegin;
|
||||
stream.on('data', (chunk) => {
|
||||
++calls.partData;
|
||||
}).on('end', () => {
|
||||
++calls.partEnd;
|
||||
});
|
||||
}).on('close', () => {
|
||||
++calls.end;
|
||||
console.timeEnd(moduleName);
|
||||
});
|
||||
|
||||
console.time(moduleName);
|
||||
for (const buf of buffers)
|
||||
parser.write(buf);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'formidable': {
|
||||
const { MultipartParser } = require('formidable');
|
||||
|
||||
const parser = new MultipartParser();
|
||||
parser.initWithBoundary(boundary);
|
||||
parser.on('data', ({ name }) => {
|
||||
++calls[name];
|
||||
if (name === 'end')
|
||||
console.timeEnd(moduleName);
|
||||
});
|
||||
|
||||
console.time(moduleName);
|
||||
for (const buf of buffers)
|
||||
parser.write(buf);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 'multiparty': {
|
||||
const { Readable } = require('stream');
|
||||
|
||||
const { Form } = require('multiparty');
|
||||
|
||||
const form = new Form({
|
||||
maxFieldsSize: Infinity,
|
||||
maxFields: Infinity,
|
||||
maxFilesSize: Infinity,
|
||||
autoFields: false,
|
||||
autoFiles: false,
|
||||
});
|
||||
|
||||
const req = new Readable({ read: () => {} });
|
||||
req.headers = {
|
||||
'content-type': `multipart/form-data; boundary=${boundary}`,
|
||||
};
|
||||
|
||||
function hijack(name, fn) {
|
||||
const oldFn = form[name];
|
||||
form[name] = function() {
|
||||
fn();
|
||||
return oldFn.apply(this, arguments);
|
||||
};
|
||||
}
|
||||
|
||||
hijack('onParseHeaderField', () => {
|
||||
++calls.headerField;
|
||||
});
|
||||
hijack('onParseHeaderValue', () => {
|
||||
++calls.headerValue;
|
||||
});
|
||||
hijack('onParsePartBegin', () => {
|
||||
++calls.partBegin;
|
||||
});
|
||||
hijack('onParsePartData', () => {
|
||||
++calls.partData;
|
||||
});
|
||||
hijack('onParsePartEnd', () => {
|
||||
++calls.partEnd;
|
||||
});
|
||||
|
||||
form.on('close', () => {
|
||||
++calls.end;
|
||||
console.timeEnd(moduleName);
|
||||
}).on('part', (p) => p.resume());
|
||||
|
||||
console.time(moduleName);
|
||||
form.parse(req);
|
||||
for (const buf of buffers)
|
||||
req.push(buf);
|
||||
req.push(null);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
if (moduleName === undefined)
|
||||
console.error('Missing parser module name');
|
||||
else
|
||||
console.error(`Invalid parser module name: ${moduleName}`);
|
||||
process.exit(1);
|
||||
}
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
'use strict';
|
||||
|
||||
function createMultipartBuffers(boundary, sizes) {
|
||||
const bufs = [];
|
||||
for (let i = 0; i < sizes.length; ++i) {
|
||||
const mb = sizes[i] * 1024 * 1024;
|
||||
bufs.push(Buffer.from([
|
||||
`--${boundary}`,
|
||||
`content-disposition: form-data; name="file${i + 1}"; `
|
||||
+ `filename="random${i + 1}.bin"`,
|
||||
'content-type: application/octet-stream',
|
||||
'',
|
||||
'0'.repeat(mb),
|
||||
'',
|
||||
].join('\r\n')));
|
||||
}
|
||||
bufs.push(Buffer.from([
|
||||
`--${boundary}--`,
|
||||
'',
|
||||
].join('\r\n')));
|
||||
return bufs;
|
||||
}
|
||||
|
||||
const boundary = '-----------------------------168072824752491622650073';
|
||||
const buffers = createMultipartBuffers(boundary, (new Array(100)).fill(1));
|
||||
const calls = {
|
||||
partBegin: 0,
|
||||
headerField: 0,
|
||||
headerValue: 0,
|
||||
headerEnd: 0,
|
||||
headersEnd: 0,
|
||||
partData: 0,
|
||||
partEnd: 0,
|
||||
end: 0,
|
||||
};
|
||||
|
||||
const moduleName = process.argv[2];
|
||||
switch (moduleName) {
|
||||
case 'busboy': {
|
||||
const busboy = require('busboy');
|
||||
|
||||
const parser = busboy({
|
||||
limits: {
|
||||
fieldSizeLimit: Infinity,
|
||||
},
|
||||
headers: {
|
||||
'content-type': `multipart/form-data; boundary=${boundary}`,
|
||||
},
|
||||
});
|
||||
parser.on('file', (name, stream, info) => {
|
||||
++calls.partBegin;
|
||||
stream.on('data', (chunk) => {
|
||||
++calls.partData;
|
||||
}).on('end', () => {
|
||||
++calls.partEnd;
|
||||
});
|
||||
}).on('close', () => {
|
||||
++calls.end;
|
||||
console.timeEnd(moduleName);
|
||||
});
|
||||
|
||||
console.time(moduleName);
|
||||
for (const buf of buffers)
|
||||
parser.write(buf);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'formidable': {
|
||||
const { MultipartParser } = require('formidable');
|
||||
|
||||
const parser = new MultipartParser();
|
||||
parser.initWithBoundary(boundary);
|
||||
parser.on('data', ({ name }) => {
|
||||
++calls[name];
|
||||
if (name === 'end')
|
||||
console.timeEnd(moduleName);
|
||||
});
|
||||
|
||||
console.time(moduleName);
|
||||
for (const buf of buffers)
|
||||
parser.write(buf);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 'multiparty': {
|
||||
const { Readable } = require('stream');
|
||||
|
||||
const { Form } = require('multiparty');
|
||||
|
||||
const form = new Form({
|
||||
maxFieldsSize: Infinity,
|
||||
maxFields: Infinity,
|
||||
maxFilesSize: Infinity,
|
||||
autoFields: false,
|
||||
autoFiles: false,
|
||||
});
|
||||
|
||||
const req = new Readable({ read: () => {} });
|
||||
req.headers = {
|
||||
'content-type': `multipart/form-data; boundary=${boundary}`,
|
||||
};
|
||||
|
||||
function hijack(name, fn) {
|
||||
const oldFn = form[name];
|
||||
form[name] = function() {
|
||||
fn();
|
||||
return oldFn.apply(this, arguments);
|
||||
};
|
||||
}
|
||||
|
||||
hijack('onParseHeaderField', () => {
|
||||
++calls.headerField;
|
||||
});
|
||||
hijack('onParseHeaderValue', () => {
|
||||
++calls.headerValue;
|
||||
});
|
||||
hijack('onParsePartBegin', () => {
|
||||
++calls.partBegin;
|
||||
});
|
||||
hijack('onParsePartData', () => {
|
||||
++calls.partData;
|
||||
});
|
||||
hijack('onParsePartEnd', () => {
|
||||
++calls.partEnd;
|
||||
});
|
||||
|
||||
form.on('close', () => {
|
||||
++calls.end;
|
||||
console.timeEnd(moduleName);
|
||||
}).on('part', (p) => p.resume());
|
||||
|
||||
console.time(moduleName);
|
||||
form.parse(req);
|
||||
for (const buf of buffers)
|
||||
req.push(buf);
|
||||
req.push(null);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
if (moduleName === undefined)
|
||||
console.error('Missing parser module name');
|
||||
else
|
||||
console.error(`Invalid parser module name: ${moduleName}`);
|
||||
process.exit(1);
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
'use strict';
|
||||
|
||||
const buffers = [
|
||||
Buffer.from(
|
||||
(new Array(100)).fill('').map((_, i) => `key${i}=value${i}`).join('&')
|
||||
),
|
||||
];
|
||||
const calls = {
|
||||
field: 0,
|
||||
end: 0,
|
||||
};
|
||||
|
||||
let n = 3e3;
|
||||
|
||||
const moduleName = process.argv[2];
|
||||
switch (moduleName) {
|
||||
case 'busboy': {
|
||||
const busboy = require('busboy');
|
||||
|
||||
console.time(moduleName);
|
||||
(function next() {
|
||||
const parser = busboy({
|
||||
limits: {
|
||||
fieldSizeLimit: Infinity,
|
||||
},
|
||||
headers: {
|
||||
'content-type': 'application/x-www-form-urlencoded; charset=utf-8',
|
||||
},
|
||||
});
|
||||
parser.on('field', (name, val, info) => {
|
||||
++calls.field;
|
||||
}).on('close', () => {
|
||||
++calls.end;
|
||||
if (--n === 0)
|
||||
console.timeEnd(moduleName);
|
||||
else
|
||||
process.nextTick(next);
|
||||
});
|
||||
|
||||
for (const buf of buffers)
|
||||
parser.write(buf);
|
||||
parser.end();
|
||||
})();
|
||||
break;
|
||||
}
|
||||
|
||||
case 'formidable': {
|
||||
const QuerystringParser =
|
||||
require('formidable/src/parsers/Querystring.js');
|
||||
|
||||
console.time(moduleName);
|
||||
(function next() {
|
||||
const parser = new QuerystringParser();
|
||||
parser.on('data', (obj) => {
|
||||
++calls.field;
|
||||
}).on('end', () => {
|
||||
++calls.end;
|
||||
if (--n === 0)
|
||||
console.timeEnd(moduleName);
|
||||
else
|
||||
process.nextTick(next);
|
||||
});
|
||||
|
||||
for (const buf of buffers)
|
||||
parser.write(buf);
|
||||
parser.end();
|
||||
})();
|
||||
break;
|
||||
}
|
||||
|
||||
case 'formidable-streaming': {
|
||||
const QuerystringParser =
|
||||
require('formidable/src/parsers/StreamingQuerystring.js');
|
||||
|
||||
console.time(moduleName);
|
||||
(function next() {
|
||||
const parser = new QuerystringParser();
|
||||
parser.on('data', (obj) => {
|
||||
++calls.field;
|
||||
}).on('end', () => {
|
||||
++calls.end;
|
||||
if (--n === 0)
|
||||
console.timeEnd(moduleName);
|
||||
else
|
||||
process.nextTick(next);
|
||||
});
|
||||
|
||||
for (const buf of buffers)
|
||||
parser.write(buf);
|
||||
parser.end();
|
||||
})();
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
if (moduleName === undefined)
|
||||
console.error('Missing parser module name');
|
||||
else
|
||||
console.error(`Invalid parser module name: ${moduleName}`);
|
||||
process.exit(1);
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
'use strict';
|
||||
|
||||
const buffers = [
|
||||
Buffer.from(
|
||||
(new Array(900)).fill('').map((_, i) => `key${i}=value${i}`).join('&')
|
||||
),
|
||||
];
|
||||
const calls = {
|
||||
field: 0,
|
||||
end: 0,
|
||||
};
|
||||
|
||||
const moduleName = process.argv[2];
|
||||
switch (moduleName) {
|
||||
case 'busboy': {
|
||||
const busboy = require('busboy');
|
||||
|
||||
console.time(moduleName);
|
||||
const parser = busboy({
|
||||
limits: {
|
||||
fieldSizeLimit: Infinity,
|
||||
},
|
||||
headers: {
|
||||
'content-type': 'application/x-www-form-urlencoded; charset=utf-8',
|
||||
},
|
||||
});
|
||||
parser.on('field', (name, val, info) => {
|
||||
++calls.field;
|
||||
}).on('close', () => {
|
||||
++calls.end;
|
||||
console.timeEnd(moduleName);
|
||||
});
|
||||
|
||||
for (const buf of buffers)
|
||||
parser.write(buf);
|
||||
parser.end();
|
||||
break;
|
||||
}
|
||||
|
||||
case 'formidable': {
|
||||
const QuerystringParser =
|
||||
require('formidable/src/parsers/Querystring.js');
|
||||
|
||||
console.time(moduleName);
|
||||
const parser = new QuerystringParser();
|
||||
parser.on('data', (obj) => {
|
||||
++calls.field;
|
||||
}).on('end', () => {
|
||||
++calls.end;
|
||||
console.timeEnd(moduleName);
|
||||
});
|
||||
|
||||
for (const buf of buffers)
|
||||
parser.write(buf);
|
||||
parser.end();
|
||||
break;
|
||||
}
|
||||
|
||||
case 'formidable-streaming': {
|
||||
const QuerystringParser =
|
||||
require('formidable/src/parsers/StreamingQuerystring.js');
|
||||
|
||||
console.time(moduleName);
|
||||
const parser = new QuerystringParser();
|
||||
parser.on('data', (obj) => {
|
||||
++calls.field;
|
||||
}).on('end', () => {
|
||||
++calls.end;
|
||||
console.timeEnd(moduleName);
|
||||
});
|
||||
|
||||
for (const buf of buffers)
|
||||
parser.write(buf);
|
||||
parser.end();
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
if (moduleName === undefined)
|
||||
console.error('Missing parser module name');
|
||||
else
|
||||
console.error(`Invalid parser module name: ${moduleName}`);
|
||||
process.exit(1);
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
'use strict';
|
||||
|
||||
const { parseContentType } = require('./utils.js');
|
||||
|
||||
function getInstance(cfg) {
|
||||
const headers = cfg.headers;
|
||||
const conType = parseContentType(headers['content-type']);
|
||||
if (!conType)
|
||||
throw new Error('Malformed content type');
|
||||
|
||||
for (const type of TYPES) {
|
||||
const matched = type.detect(conType);
|
||||
if (!matched)
|
||||
continue;
|
||||
|
||||
const instanceCfg = {
|
||||
limits: cfg.limits,
|
||||
headers,
|
||||
conType,
|
||||
highWaterMark: undefined,
|
||||
fileHwm: undefined,
|
||||
defCharset: undefined,
|
||||
defParamCharset: undefined,
|
||||
preservePath: false,
|
||||
};
|
||||
if (cfg.highWaterMark)
|
||||
instanceCfg.highWaterMark = cfg.highWaterMark;
|
||||
if (cfg.fileHwm)
|
||||
instanceCfg.fileHwm = cfg.fileHwm;
|
||||
instanceCfg.defCharset = cfg.defCharset;
|
||||
instanceCfg.defParamCharset = cfg.defParamCharset;
|
||||
instanceCfg.preservePath = cfg.preservePath;
|
||||
return new type(instanceCfg);
|
||||
}
|
||||
|
||||
throw new Error(`Unsupported content type: ${headers['content-type']}`);
|
||||
}
|
||||
|
||||
// Note: types are explicitly listed here for easier bundling
|
||||
// See: https://github.com/mscdex/busboy/issues/121
|
||||
const TYPES = [
|
||||
require('./types/multipart'),
|
||||
require('./types/urlencoded'),
|
||||
].filter(function(typemod) { return typeof typemod.detect === 'function'; });
|
||||
|
||||
module.exports = (cfg) => {
|
||||
if (typeof cfg !== 'object' || cfg === null)
|
||||
cfg = {};
|
||||
|
||||
if (typeof cfg.headers !== 'object'
|
||||
|| cfg.headers === null
|
||||
|| typeof cfg.headers['content-type'] !== 'string') {
|
||||
throw new Error('Missing Content-Type');
|
||||
}
|
||||
|
||||
return getInstance(cfg);
|
||||
};
|
||||
+653
@@ -0,0 +1,653 @@
|
||||
'use strict';
|
||||
|
||||
const { Readable, Writable } = require('stream');
|
||||
|
||||
const StreamSearch = require('streamsearch');
|
||||
|
||||
const {
|
||||
basename,
|
||||
convertToUTF8,
|
||||
getDecoder,
|
||||
parseContentType,
|
||||
parseDisposition,
|
||||
} = require('../utils.js');
|
||||
|
||||
const BUF_CRLF = Buffer.from('\r\n');
|
||||
const BUF_CR = Buffer.from('\r');
|
||||
const BUF_DASH = Buffer.from('-');
|
||||
|
||||
function noop() {}
|
||||
|
||||
const MAX_HEADER_PAIRS = 2000; // From node
|
||||
const MAX_HEADER_SIZE = 16 * 1024; // From node (its default value)
|
||||
|
||||
const HPARSER_NAME = 0;
|
||||
const HPARSER_PRE_OWS = 1;
|
||||
const HPARSER_VALUE = 2;
|
||||
class HeaderParser {
|
||||
constructor(cb) {
|
||||
this.header = Object.create(null);
|
||||
this.pairCount = 0;
|
||||
this.byteCount = 0;
|
||||
this.state = HPARSER_NAME;
|
||||
this.name = '';
|
||||
this.value = '';
|
||||
this.crlf = 0;
|
||||
this.cb = cb;
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.header = Object.create(null);
|
||||
this.pairCount = 0;
|
||||
this.byteCount = 0;
|
||||
this.state = HPARSER_NAME;
|
||||
this.name = '';
|
||||
this.value = '';
|
||||
this.crlf = 0;
|
||||
}
|
||||
|
||||
push(chunk, pos, end) {
|
||||
let start = pos;
|
||||
while (pos < end) {
|
||||
switch (this.state) {
|
||||
case HPARSER_NAME: {
|
||||
let done = false;
|
||||
for (; pos < end; ++pos) {
|
||||
if (this.byteCount === MAX_HEADER_SIZE)
|
||||
return -1;
|
||||
++this.byteCount;
|
||||
const code = chunk[pos];
|
||||
if (TOKEN[code] !== 1) {
|
||||
if (code !== 58/* ':' */)
|
||||
return -1;
|
||||
this.name += chunk.latin1Slice(start, pos);
|
||||
if (this.name.length === 0)
|
||||
return -1;
|
||||
++pos;
|
||||
done = true;
|
||||
this.state = HPARSER_PRE_OWS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!done) {
|
||||
this.name += chunk.latin1Slice(start, pos);
|
||||
break;
|
||||
}
|
||||
// FALLTHROUGH
|
||||
}
|
||||
case HPARSER_PRE_OWS: {
|
||||
// Skip optional whitespace
|
||||
let done = false;
|
||||
for (; pos < end; ++pos) {
|
||||
if (this.byteCount === MAX_HEADER_SIZE)
|
||||
return -1;
|
||||
++this.byteCount;
|
||||
const code = chunk[pos];
|
||||
if (code !== 32/* ' ' */ && code !== 9/* '\t' */) {
|
||||
start = pos;
|
||||
done = true;
|
||||
this.state = HPARSER_VALUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!done)
|
||||
break;
|
||||
// FALLTHROUGH
|
||||
}
|
||||
case HPARSER_VALUE:
|
||||
switch (this.crlf) {
|
||||
case 0: // Nothing yet
|
||||
for (; pos < end; ++pos) {
|
||||
if (this.byteCount === MAX_HEADER_SIZE)
|
||||
return -1;
|
||||
++this.byteCount;
|
||||
const code = chunk[pos];
|
||||
if (FIELD_VCHAR[code] !== 1) {
|
||||
if (code !== 13/* '\r' */)
|
||||
return -1;
|
||||
++this.crlf;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.value += chunk.latin1Slice(start, pos++);
|
||||
break;
|
||||
case 1: // Received CR
|
||||
if (this.byteCount === MAX_HEADER_SIZE)
|
||||
return -1;
|
||||
++this.byteCount;
|
||||
if (chunk[pos++] !== 10/* '\n' */)
|
||||
return -1;
|
||||
++this.crlf;
|
||||
break;
|
||||
case 2: { // Received CR LF
|
||||
if (this.byteCount === MAX_HEADER_SIZE)
|
||||
return -1;
|
||||
++this.byteCount;
|
||||
const code = chunk[pos];
|
||||
if (code === 32/* ' ' */ || code === 9/* '\t' */) {
|
||||
// Folded value
|
||||
start = pos;
|
||||
this.crlf = 0;
|
||||
} else {
|
||||
if (++this.pairCount < MAX_HEADER_PAIRS) {
|
||||
this.name = this.name.toLowerCase();
|
||||
if (this.header[this.name] === undefined)
|
||||
this.header[this.name] = [this.value];
|
||||
else
|
||||
this.header[this.name].push(this.value);
|
||||
}
|
||||
if (code === 13/* '\r' */) {
|
||||
++this.crlf;
|
||||
++pos;
|
||||
} else {
|
||||
// Assume start of next header field name
|
||||
start = pos;
|
||||
this.crlf = 0;
|
||||
this.state = HPARSER_NAME;
|
||||
this.name = '';
|
||||
this.value = '';
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3: { // Received CR LF CR
|
||||
if (this.byteCount === MAX_HEADER_SIZE)
|
||||
return -1;
|
||||
++this.byteCount;
|
||||
if (chunk[pos++] !== 10/* '\n' */)
|
||||
return -1;
|
||||
// End of header
|
||||
const header = this.header;
|
||||
this.reset();
|
||||
this.cb(header);
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
|
||||
class FileStream extends Readable {
|
||||
constructor(opts, owner) {
|
||||
super(opts);
|
||||
this.truncated = false;
|
||||
this._readcb = null;
|
||||
this.once('end', () => {
|
||||
// We need to make sure that we call any outstanding _writecb() that is
|
||||
// associated with this file so that processing of the rest of the form
|
||||
// can continue. This may not happen if the file stream ends right after
|
||||
// backpressure kicks in, so we force it here.
|
||||
this._read();
|
||||
if (--owner._fileEndsLeft === 0 && owner._finalcb) {
|
||||
const cb = owner._finalcb;
|
||||
owner._finalcb = null;
|
||||
// Make sure other 'end' event handlers get a chance to be executed
|
||||
// before busboy's 'finish' event is emitted
|
||||
process.nextTick(cb);
|
||||
}
|
||||
});
|
||||
}
|
||||
_read(n) {
|
||||
const cb = this._readcb;
|
||||
if (cb) {
|
||||
this._readcb = null;
|
||||
cb();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const ignoreData = {
|
||||
push: (chunk, pos) => {},
|
||||
destroy: () => {},
|
||||
};
|
||||
|
||||
function callAndUnsetCb(self, err) {
|
||||
const cb = self._writecb;
|
||||
self._writecb = null;
|
||||
if (err)
|
||||
self.destroy(err);
|
||||
else if (cb)
|
||||
cb();
|
||||
}
|
||||
|
||||
function nullDecoder(val, hint) {
|
||||
return val;
|
||||
}
|
||||
|
||||
class Multipart extends Writable {
|
||||
constructor(cfg) {
|
||||
const streamOpts = {
|
||||
autoDestroy: true,
|
||||
emitClose: true,
|
||||
highWaterMark: (typeof cfg.highWaterMark === 'number'
|
||||
? cfg.highWaterMark
|
||||
: undefined),
|
||||
};
|
||||
super(streamOpts);
|
||||
|
||||
if (!cfg.conType.params || typeof cfg.conType.params.boundary !== 'string')
|
||||
throw new Error('Multipart: Boundary not found');
|
||||
|
||||
const boundary = cfg.conType.params.boundary;
|
||||
const paramDecoder = (typeof cfg.defParamCharset === 'string'
|
||||
&& cfg.defParamCharset
|
||||
? getDecoder(cfg.defParamCharset)
|
||||
: nullDecoder);
|
||||
const defCharset = (cfg.defCharset || 'utf8');
|
||||
const preservePath = cfg.preservePath;
|
||||
const fileOpts = {
|
||||
autoDestroy: true,
|
||||
emitClose: true,
|
||||
highWaterMark: (typeof cfg.fileHwm === 'number'
|
||||
? cfg.fileHwm
|
||||
: undefined),
|
||||
};
|
||||
|
||||
const limits = cfg.limits;
|
||||
const fieldSizeLimit = (limits && typeof limits.fieldSize === 'number'
|
||||
? limits.fieldSize
|
||||
: 1 * 1024 * 1024);
|
||||
const fileSizeLimit = (limits && typeof limits.fileSize === 'number'
|
||||
? limits.fileSize
|
||||
: Infinity);
|
||||
const filesLimit = (limits && typeof limits.files === 'number'
|
||||
? limits.files
|
||||
: Infinity);
|
||||
const fieldsLimit = (limits && typeof limits.fields === 'number'
|
||||
? limits.fields
|
||||
: Infinity);
|
||||
const partsLimit = (limits && typeof limits.parts === 'number'
|
||||
? limits.parts
|
||||
: Infinity);
|
||||
|
||||
let parts = -1; // Account for initial boundary
|
||||
let fields = 0;
|
||||
let files = 0;
|
||||
let skipPart = false;
|
||||
|
||||
this._fileEndsLeft = 0;
|
||||
this._fileStream = undefined;
|
||||
this._complete = false;
|
||||
let fileSize = 0;
|
||||
|
||||
let field;
|
||||
let fieldSize = 0;
|
||||
let partCharset;
|
||||
let partEncoding;
|
||||
let partType;
|
||||
let partName;
|
||||
let partTruncated = false;
|
||||
|
||||
let hitFilesLimit = false;
|
||||
let hitFieldsLimit = false;
|
||||
|
||||
this._hparser = null;
|
||||
const hparser = new HeaderParser((header) => {
|
||||
this._hparser = null;
|
||||
skipPart = false;
|
||||
|
||||
partType = 'text/plain';
|
||||
partCharset = defCharset;
|
||||
partEncoding = '7bit';
|
||||
partName = undefined;
|
||||
partTruncated = false;
|
||||
|
||||
let filename;
|
||||
if (!header['content-disposition']) {
|
||||
skipPart = true;
|
||||
return;
|
||||
}
|
||||
|
||||
const disp = parseDisposition(header['content-disposition'][0],
|
||||
paramDecoder);
|
||||
if (!disp || disp.type !== 'form-data') {
|
||||
skipPart = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (disp.params) {
|
||||
if (disp.params.name)
|
||||
partName = disp.params.name;
|
||||
|
||||
if (disp.params['filename*'])
|
||||
filename = disp.params['filename*'];
|
||||
else if (disp.params.filename)
|
||||
filename = disp.params.filename;
|
||||
|
||||
if (filename !== undefined && !preservePath)
|
||||
filename = basename(filename);
|
||||
}
|
||||
|
||||
if (header['content-type']) {
|
||||
const conType = parseContentType(header['content-type'][0]);
|
||||
if (conType) {
|
||||
partType = `${conType.type}/${conType.subtype}`;
|
||||
if (conType.params && typeof conType.params.charset === 'string')
|
||||
partCharset = conType.params.charset.toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
if (header['content-transfer-encoding'])
|
||||
partEncoding = header['content-transfer-encoding'][0].toLowerCase();
|
||||
|
||||
if (partType === 'application/octet-stream' || filename !== undefined) {
|
||||
// File
|
||||
|
||||
if (files === filesLimit) {
|
||||
if (!hitFilesLimit) {
|
||||
hitFilesLimit = true;
|
||||
this.emit('filesLimit');
|
||||
}
|
||||
skipPart = true;
|
||||
return;
|
||||
}
|
||||
++files;
|
||||
|
||||
if (this.listenerCount('file') === 0) {
|
||||
skipPart = true;
|
||||
return;
|
||||
}
|
||||
|
||||
fileSize = 0;
|
||||
this._fileStream = new FileStream(fileOpts, this);
|
||||
++this._fileEndsLeft;
|
||||
this.emit(
|
||||
'file',
|
||||
partName,
|
||||
this._fileStream,
|
||||
{ filename,
|
||||
encoding: partEncoding,
|
||||
mimeType: partType }
|
||||
);
|
||||
} else {
|
||||
// Non-file
|
||||
|
||||
if (fields === fieldsLimit) {
|
||||
if (!hitFieldsLimit) {
|
||||
hitFieldsLimit = true;
|
||||
this.emit('fieldsLimit');
|
||||
}
|
||||
skipPart = true;
|
||||
return;
|
||||
}
|
||||
++fields;
|
||||
|
||||
if (this.listenerCount('field') === 0) {
|
||||
skipPart = true;
|
||||
return;
|
||||
}
|
||||
|
||||
field = [];
|
||||
fieldSize = 0;
|
||||
}
|
||||
});
|
||||
|
||||
let matchPostBoundary = 0;
|
||||
const ssCb = (isMatch, data, start, end, isDataSafe) => {
|
||||
retrydata:
|
||||
while (data) {
|
||||
if (this._hparser !== null) {
|
||||
const ret = this._hparser.push(data, start, end);
|
||||
if (ret === -1) {
|
||||
this._hparser = null;
|
||||
hparser.reset();
|
||||
this.emit('error', new Error('Malformed part header'));
|
||||
break;
|
||||
}
|
||||
start = ret;
|
||||
}
|
||||
|
||||
if (start === end)
|
||||
break;
|
||||
|
||||
if (matchPostBoundary !== 0) {
|
||||
if (matchPostBoundary === 1) {
|
||||
switch (data[start]) {
|
||||
case 45: // '-'
|
||||
// Try matching '--' after boundary
|
||||
matchPostBoundary = 2;
|
||||
++start;
|
||||
break;
|
||||
case 13: // '\r'
|
||||
// Try matching CR LF before header
|
||||
matchPostBoundary = 3;
|
||||
++start;
|
||||
break;
|
||||
default:
|
||||
matchPostBoundary = 0;
|
||||
}
|
||||
if (start === end)
|
||||
return;
|
||||
}
|
||||
|
||||
if (matchPostBoundary === 2) {
|
||||
matchPostBoundary = 0;
|
||||
if (data[start] === 45/* '-' */) {
|
||||
// End of multipart data
|
||||
this._complete = true;
|
||||
this._bparser = ignoreData;
|
||||
return;
|
||||
}
|
||||
// We saw something other than '-', so put the dash we consumed
|
||||
// "back"
|
||||
const writecb = this._writecb;
|
||||
this._writecb = noop;
|
||||
ssCb(false, BUF_DASH, 0, 1, false);
|
||||
this._writecb = writecb;
|
||||
} else if (matchPostBoundary === 3) {
|
||||
matchPostBoundary = 0;
|
||||
if (data[start] === 10/* '\n' */) {
|
||||
++start;
|
||||
if (parts >= partsLimit)
|
||||
break;
|
||||
// Prepare the header parser
|
||||
this._hparser = hparser;
|
||||
if (start === end)
|
||||
break;
|
||||
// Process the remaining data as a header
|
||||
continue retrydata;
|
||||
} else {
|
||||
// We saw something other than LF, so put the CR we consumed
|
||||
// "back"
|
||||
const writecb = this._writecb;
|
||||
this._writecb = noop;
|
||||
ssCb(false, BUF_CR, 0, 1, false);
|
||||
this._writecb = writecb;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!skipPart) {
|
||||
if (this._fileStream) {
|
||||
let chunk;
|
||||
const actualLen = Math.min(end - start, fileSizeLimit - fileSize);
|
||||
if (!isDataSafe) {
|
||||
chunk = Buffer.allocUnsafe(actualLen);
|
||||
data.copy(chunk, 0, start, start + actualLen);
|
||||
} else {
|
||||
chunk = data.slice(start, start + actualLen);
|
||||
}
|
||||
|
||||
fileSize += chunk.length;
|
||||
if (fileSize === fileSizeLimit) {
|
||||
if (chunk.length > 0)
|
||||
this._fileStream.push(chunk);
|
||||
this._fileStream.emit('limit');
|
||||
this._fileStream.truncated = true;
|
||||
skipPart = true;
|
||||
} else if (!this._fileStream.push(chunk)) {
|
||||
if (this._writecb)
|
||||
this._fileStream._readcb = this._writecb;
|
||||
this._writecb = null;
|
||||
}
|
||||
} else if (field !== undefined) {
|
||||
let chunk;
|
||||
const actualLen = Math.min(
|
||||
end - start,
|
||||
fieldSizeLimit - fieldSize
|
||||
);
|
||||
if (!isDataSafe) {
|
||||
chunk = Buffer.allocUnsafe(actualLen);
|
||||
data.copy(chunk, 0, start, start + actualLen);
|
||||
} else {
|
||||
chunk = data.slice(start, start + actualLen);
|
||||
}
|
||||
|
||||
fieldSize += actualLen;
|
||||
field.push(chunk);
|
||||
if (fieldSize === fieldSizeLimit) {
|
||||
skipPart = true;
|
||||
partTruncated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (isMatch) {
|
||||
matchPostBoundary = 1;
|
||||
|
||||
if (this._fileStream) {
|
||||
// End the active file stream if the previous part was a file
|
||||
this._fileStream.push(null);
|
||||
this._fileStream = null;
|
||||
} else if (field !== undefined) {
|
||||
let data;
|
||||
switch (field.length) {
|
||||
case 0:
|
||||
data = '';
|
||||
break;
|
||||
case 1:
|
||||
data = convertToUTF8(field[0], partCharset, 0);
|
||||
break;
|
||||
default:
|
||||
data = convertToUTF8(
|
||||
Buffer.concat(field, fieldSize),
|
||||
partCharset,
|
||||
0
|
||||
);
|
||||
}
|
||||
field = undefined;
|
||||
fieldSize = 0;
|
||||
this.emit(
|
||||
'field',
|
||||
partName,
|
||||
data,
|
||||
{ nameTruncated: false,
|
||||
valueTruncated: partTruncated,
|
||||
encoding: partEncoding,
|
||||
mimeType: partType }
|
||||
);
|
||||
}
|
||||
|
||||
if (++parts === partsLimit)
|
||||
this.emit('partsLimit');
|
||||
}
|
||||
};
|
||||
this._bparser = new StreamSearch(`\r\n--${boundary}`, ssCb);
|
||||
|
||||
this._writecb = null;
|
||||
this._finalcb = null;
|
||||
|
||||
// Just in case there is no preamble
|
||||
this.write(BUF_CRLF);
|
||||
}
|
||||
|
||||
static detect(conType) {
|
||||
return (conType.type === 'multipart' && conType.subtype === 'form-data');
|
||||
}
|
||||
|
||||
_write(chunk, enc, cb) {
|
||||
this._writecb = cb;
|
||||
this._bparser.push(chunk, 0);
|
||||
if (this._writecb)
|
||||
callAndUnsetCb(this);
|
||||
}
|
||||
|
||||
_destroy(err, cb) {
|
||||
this._hparser = null;
|
||||
this._bparser = ignoreData;
|
||||
if (!err)
|
||||
err = checkEndState(this);
|
||||
const fileStream = this._fileStream;
|
||||
if (fileStream) {
|
||||
this._fileStream = null;
|
||||
fileStream.destroy(err);
|
||||
}
|
||||
cb(err);
|
||||
}
|
||||
|
||||
_final(cb) {
|
||||
this._bparser.destroy();
|
||||
if (!this._complete)
|
||||
return cb(new Error('Unexpected end of form'));
|
||||
if (this._fileEndsLeft)
|
||||
this._finalcb = finalcb.bind(null, this, cb);
|
||||
else
|
||||
finalcb(this, cb);
|
||||
}
|
||||
}
|
||||
|
||||
function finalcb(self, cb, err) {
|
||||
if (err)
|
||||
return cb(err);
|
||||
err = checkEndState(self);
|
||||
cb(err);
|
||||
}
|
||||
|
||||
function checkEndState(self) {
|
||||
if (self._hparser)
|
||||
return new Error('Malformed part header');
|
||||
const fileStream = self._fileStream;
|
||||
if (fileStream) {
|
||||
self._fileStream = null;
|
||||
fileStream.destroy(new Error('Unexpected end of file'));
|
||||
}
|
||||
if (!self._complete)
|
||||
return new Error('Unexpected end of form');
|
||||
}
|
||||
|
||||
const TOKEN = [
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
|
||||
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
|
||||
const FIELD_VCHAR = [
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
];
|
||||
|
||||
module.exports = Multipart;
|
||||
+350
@@ -0,0 +1,350 @@
|
||||
'use strict';
|
||||
|
||||
const { Writable } = require('stream');
|
||||
|
||||
const { getDecoder } = require('../utils.js');
|
||||
|
||||
class URLEncoded extends Writable {
|
||||
constructor(cfg) {
|
||||
const streamOpts = {
|
||||
autoDestroy: true,
|
||||
emitClose: true,
|
||||
highWaterMark: (typeof cfg.highWaterMark === 'number'
|
||||
? cfg.highWaterMark
|
||||
: undefined),
|
||||
};
|
||||
super(streamOpts);
|
||||
|
||||
let charset = (cfg.defCharset || 'utf8');
|
||||
if (cfg.conType.params && typeof cfg.conType.params.charset === 'string')
|
||||
charset = cfg.conType.params.charset;
|
||||
|
||||
this.charset = charset;
|
||||
|
||||
const limits = cfg.limits;
|
||||
this.fieldSizeLimit = (limits && typeof limits.fieldSize === 'number'
|
||||
? limits.fieldSize
|
||||
: 1 * 1024 * 1024);
|
||||
this.fieldsLimit = (limits && typeof limits.fields === 'number'
|
||||
? limits.fields
|
||||
: Infinity);
|
||||
this.fieldNameSizeLimit = (
|
||||
limits && typeof limits.fieldNameSize === 'number'
|
||||
? limits.fieldNameSize
|
||||
: 100
|
||||
);
|
||||
|
||||
this._inKey = true;
|
||||
this._keyTrunc = false;
|
||||
this._valTrunc = false;
|
||||
this._bytesKey = 0;
|
||||
this._bytesVal = 0;
|
||||
this._fields = 0;
|
||||
this._key = '';
|
||||
this._val = '';
|
||||
this._byte = -2;
|
||||
this._lastPos = 0;
|
||||
this._encode = 0;
|
||||
this._decoder = getDecoder(charset);
|
||||
}
|
||||
|
||||
static detect(conType) {
|
||||
return (conType.type === 'application'
|
||||
&& conType.subtype === 'x-www-form-urlencoded');
|
||||
}
|
||||
|
||||
_write(chunk, enc, cb) {
|
||||
if (this._fields >= this.fieldsLimit)
|
||||
return cb();
|
||||
|
||||
let i = 0;
|
||||
const len = chunk.length;
|
||||
this._lastPos = 0;
|
||||
|
||||
// Check if we last ended mid-percent-encoded byte
|
||||
if (this._byte !== -2) {
|
||||
i = readPctEnc(this, chunk, i, len);
|
||||
if (i === -1)
|
||||
return cb(new Error('Malformed urlencoded form'));
|
||||
if (i >= len)
|
||||
return cb();
|
||||
if (this._inKey)
|
||||
++this._bytesKey;
|
||||
else
|
||||
++this._bytesVal;
|
||||
}
|
||||
|
||||
main:
|
||||
while (i < len) {
|
||||
if (this._inKey) {
|
||||
// Parsing key
|
||||
|
||||
i = skipKeyBytes(this, chunk, i, len);
|
||||
|
||||
while (i < len) {
|
||||
switch (chunk[i]) {
|
||||
case 61: // '='
|
||||
if (this._lastPos < i)
|
||||
this._key += chunk.latin1Slice(this._lastPos, i);
|
||||
this._lastPos = ++i;
|
||||
this._key = this._decoder(this._key, this._encode);
|
||||
this._encode = 0;
|
||||
this._inKey = false;
|
||||
continue main;
|
||||
case 38: // '&'
|
||||
if (this._lastPos < i)
|
||||
this._key += chunk.latin1Slice(this._lastPos, i);
|
||||
this._lastPos = ++i;
|
||||
this._key = this._decoder(this._key, this._encode);
|
||||
this._encode = 0;
|
||||
if (this._bytesKey > 0) {
|
||||
this.emit(
|
||||
'field',
|
||||
this._key,
|
||||
'',
|
||||
{ nameTruncated: this._keyTrunc,
|
||||
valueTruncated: false,
|
||||
encoding: this.charset,
|
||||
mimeType: 'text/plain' }
|
||||
);
|
||||
}
|
||||
this._key = '';
|
||||
this._val = '';
|
||||
this._keyTrunc = false;
|
||||
this._valTrunc = false;
|
||||
this._bytesKey = 0;
|
||||
this._bytesVal = 0;
|
||||
if (++this._fields >= this.fieldsLimit) {
|
||||
this.emit('fieldsLimit');
|
||||
return cb();
|
||||
}
|
||||
continue;
|
||||
case 43: // '+'
|
||||
if (this._lastPos < i)
|
||||
this._key += chunk.latin1Slice(this._lastPos, i);
|
||||
this._key += ' ';
|
||||
this._lastPos = i + 1;
|
||||
break;
|
||||
case 37: // '%'
|
||||
if (this._encode === 0)
|
||||
this._encode = 1;
|
||||
if (this._lastPos < i)
|
||||
this._key += chunk.latin1Slice(this._lastPos, i);
|
||||
this._lastPos = i + 1;
|
||||
this._byte = -1;
|
||||
i = readPctEnc(this, chunk, i + 1, len);
|
||||
if (i === -1)
|
||||
return cb(new Error('Malformed urlencoded form'));
|
||||
if (i >= len)
|
||||
return cb();
|
||||
++this._bytesKey;
|
||||
i = skipKeyBytes(this, chunk, i, len);
|
||||
continue;
|
||||
}
|
||||
++i;
|
||||
++this._bytesKey;
|
||||
i = skipKeyBytes(this, chunk, i, len);
|
||||
}
|
||||
if (this._lastPos < i)
|
||||
this._key += chunk.latin1Slice(this._lastPos, i);
|
||||
} else {
|
||||
// Parsing value
|
||||
|
||||
i = skipValBytes(this, chunk, i, len);
|
||||
|
||||
while (i < len) {
|
||||
switch (chunk[i]) {
|
||||
case 38: // '&'
|
||||
if (this._lastPos < i)
|
||||
this._val += chunk.latin1Slice(this._lastPos, i);
|
||||
this._lastPos = ++i;
|
||||
this._inKey = true;
|
||||
this._val = this._decoder(this._val, this._encode);
|
||||
this._encode = 0;
|
||||
if (this._bytesKey > 0 || this._bytesVal > 0) {
|
||||
this.emit(
|
||||
'field',
|
||||
this._key,
|
||||
this._val,
|
||||
{ nameTruncated: this._keyTrunc,
|
||||
valueTruncated: this._valTrunc,
|
||||
encoding: this.charset,
|
||||
mimeType: 'text/plain' }
|
||||
);
|
||||
}
|
||||
this._key = '';
|
||||
this._val = '';
|
||||
this._keyTrunc = false;
|
||||
this._valTrunc = false;
|
||||
this._bytesKey = 0;
|
||||
this._bytesVal = 0;
|
||||
if (++this._fields >= this.fieldsLimit) {
|
||||
this.emit('fieldsLimit');
|
||||
return cb();
|
||||
}
|
||||
continue main;
|
||||
case 43: // '+'
|
||||
if (this._lastPos < i)
|
||||
this._val += chunk.latin1Slice(this._lastPos, i);
|
||||
this._val += ' ';
|
||||
this._lastPos = i + 1;
|
||||
break;
|
||||
case 37: // '%'
|
||||
if (this._encode === 0)
|
||||
this._encode = 1;
|
||||
if (this._lastPos < i)
|
||||
this._val += chunk.latin1Slice(this._lastPos, i);
|
||||
this._lastPos = i + 1;
|
||||
this._byte = -1;
|
||||
i = readPctEnc(this, chunk, i + 1, len);
|
||||
if (i === -1)
|
||||
return cb(new Error('Malformed urlencoded form'));
|
||||
if (i >= len)
|
||||
return cb();
|
||||
++this._bytesVal;
|
||||
i = skipValBytes(this, chunk, i, len);
|
||||
continue;
|
||||
}
|
||||
++i;
|
||||
++this._bytesVal;
|
||||
i = skipValBytes(this, chunk, i, len);
|
||||
}
|
||||
if (this._lastPos < i)
|
||||
this._val += chunk.latin1Slice(this._lastPos, i);
|
||||
}
|
||||
}
|
||||
|
||||
cb();
|
||||
}
|
||||
|
||||
_final(cb) {
|
||||
if (this._byte !== -2)
|
||||
return cb(new Error('Malformed urlencoded form'));
|
||||
if (!this._inKey || this._bytesKey > 0 || this._bytesVal > 0) {
|
||||
if (this._inKey)
|
||||
this._key = this._decoder(this._key, this._encode);
|
||||
else
|
||||
this._val = this._decoder(this._val, this._encode);
|
||||
this.emit(
|
||||
'field',
|
||||
this._key,
|
||||
this._val,
|
||||
{ nameTruncated: this._keyTrunc,
|
||||
valueTruncated: this._valTrunc,
|
||||
encoding: this.charset,
|
||||
mimeType: 'text/plain' }
|
||||
);
|
||||
}
|
||||
cb();
|
||||
}
|
||||
}
|
||||
|
||||
function readPctEnc(self, chunk, pos, len) {
|
||||
if (pos >= len)
|
||||
return len;
|
||||
|
||||
if (self._byte === -1) {
|
||||
// We saw a '%' but no hex characters yet
|
||||
const hexUpper = HEX_VALUES[chunk[pos++]];
|
||||
if (hexUpper === -1)
|
||||
return -1;
|
||||
|
||||
if (hexUpper >= 8)
|
||||
self._encode = 2; // Indicate high bits detected
|
||||
|
||||
if (pos < len) {
|
||||
// Both hex characters are in this chunk
|
||||
const hexLower = HEX_VALUES[chunk[pos++]];
|
||||
if (hexLower === -1)
|
||||
return -1;
|
||||
|
||||
if (self._inKey)
|
||||
self._key += String.fromCharCode((hexUpper << 4) + hexLower);
|
||||
else
|
||||
self._val += String.fromCharCode((hexUpper << 4) + hexLower);
|
||||
|
||||
self._byte = -2;
|
||||
self._lastPos = pos;
|
||||
} else {
|
||||
// Only one hex character was available in this chunk
|
||||
self._byte = hexUpper;
|
||||
}
|
||||
} else {
|
||||
// We saw only one hex character so far
|
||||
const hexLower = HEX_VALUES[chunk[pos++]];
|
||||
if (hexLower === -1)
|
||||
return -1;
|
||||
|
||||
if (self._inKey)
|
||||
self._key += String.fromCharCode((self._byte << 4) + hexLower);
|
||||
else
|
||||
self._val += String.fromCharCode((self._byte << 4) + hexLower);
|
||||
|
||||
self._byte = -2;
|
||||
self._lastPos = pos;
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
function skipKeyBytes(self, chunk, pos, len) {
|
||||
// Skip bytes if we've truncated
|
||||
if (self._bytesKey > self.fieldNameSizeLimit) {
|
||||
if (!self._keyTrunc) {
|
||||
if (self._lastPos < pos)
|
||||
self._key += chunk.latin1Slice(self._lastPos, pos - 1);
|
||||
}
|
||||
self._keyTrunc = true;
|
||||
for (; pos < len; ++pos) {
|
||||
const code = chunk[pos];
|
||||
if (code === 61/* '=' */ || code === 38/* '&' */)
|
||||
break;
|
||||
++self._bytesKey;
|
||||
}
|
||||
self._lastPos = pos;
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
function skipValBytes(self, chunk, pos, len) {
|
||||
// Skip bytes if we've truncated
|
||||
if (self._bytesVal > self.fieldSizeLimit) {
|
||||
if (!self._valTrunc) {
|
||||
if (self._lastPos < pos)
|
||||
self._val += chunk.latin1Slice(self._lastPos, pos - 1);
|
||||
}
|
||||
self._valTrunc = true;
|
||||
for (; pos < len; ++pos) {
|
||||
if (chunk[pos] === 38/* '&' */)
|
||||
break;
|
||||
++self._bytesVal;
|
||||
}
|
||||
self._lastPos = pos;
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
/* eslint-disable no-multi-spaces */
|
||||
const HEX_VALUES = [
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
|
||||
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
];
|
||||
/* eslint-enable no-multi-spaces */
|
||||
|
||||
module.exports = URLEncoded;
|
||||
+596
@@ -0,0 +1,596 @@
|
||||
'use strict';
|
||||
|
||||
function parseContentType(str) {
|
||||
if (str.length === 0)
|
||||
return;
|
||||
|
||||
const params = Object.create(null);
|
||||
let i = 0;
|
||||
|
||||
// Parse type
|
||||
for (; i < str.length; ++i) {
|
||||
const code = str.charCodeAt(i);
|
||||
if (TOKEN[code] !== 1) {
|
||||
if (code !== 47/* '/' */ || i === 0)
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Check for type without subtype
|
||||
if (i === str.length)
|
||||
return;
|
||||
|
||||
const type = str.slice(0, i).toLowerCase();
|
||||
|
||||
// Parse subtype
|
||||
const subtypeStart = ++i;
|
||||
for (; i < str.length; ++i) {
|
||||
const code = str.charCodeAt(i);
|
||||
if (TOKEN[code] !== 1) {
|
||||
// Make sure we have a subtype
|
||||
if (i === subtypeStart)
|
||||
return;
|
||||
|
||||
if (parseContentTypeParams(str, i, params) === undefined)
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Make sure we have a subtype
|
||||
if (i === subtypeStart)
|
||||
return;
|
||||
|
||||
const subtype = str.slice(subtypeStart, i).toLowerCase();
|
||||
|
||||
return { type, subtype, params };
|
||||
}
|
||||
|
||||
function parseContentTypeParams(str, i, params) {
|
||||
while (i < str.length) {
|
||||
// Consume whitespace
|
||||
for (; i < str.length; ++i) {
|
||||
const code = str.charCodeAt(i);
|
||||
if (code !== 32/* ' ' */ && code !== 9/* '\t' */)
|
||||
break;
|
||||
}
|
||||
|
||||
// Ended on whitespace
|
||||
if (i === str.length)
|
||||
break;
|
||||
|
||||
// Check for malformed parameter
|
||||
if (str.charCodeAt(i++) !== 59/* ';' */)
|
||||
return;
|
||||
|
||||
// Consume whitespace
|
||||
for (; i < str.length; ++i) {
|
||||
const code = str.charCodeAt(i);
|
||||
if (code !== 32/* ' ' */ && code !== 9/* '\t' */)
|
||||
break;
|
||||
}
|
||||
|
||||
// Ended on whitespace (malformed)
|
||||
if (i === str.length)
|
||||
return;
|
||||
|
||||
let name;
|
||||
const nameStart = i;
|
||||
// Parse parameter name
|
||||
for (; i < str.length; ++i) {
|
||||
const code = str.charCodeAt(i);
|
||||
if (TOKEN[code] !== 1) {
|
||||
if (code !== 61/* '=' */)
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// No value (malformed)
|
||||
if (i === str.length)
|
||||
return;
|
||||
|
||||
name = str.slice(nameStart, i);
|
||||
++i; // Skip over '='
|
||||
|
||||
// No value (malformed)
|
||||
if (i === str.length)
|
||||
return;
|
||||
|
||||
let value = '';
|
||||
let valueStart;
|
||||
if (str.charCodeAt(i) === 34/* '"' */) {
|
||||
valueStart = ++i;
|
||||
let escaping = false;
|
||||
// Parse quoted value
|
||||
for (; i < str.length; ++i) {
|
||||
const code = str.charCodeAt(i);
|
||||
if (code === 92/* '\\' */) {
|
||||
if (escaping) {
|
||||
valueStart = i;
|
||||
escaping = false;
|
||||
} else {
|
||||
value += str.slice(valueStart, i);
|
||||
escaping = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (code === 34/* '"' */) {
|
||||
if (escaping) {
|
||||
valueStart = i;
|
||||
escaping = false;
|
||||
continue;
|
||||
}
|
||||
value += str.slice(valueStart, i);
|
||||
break;
|
||||
}
|
||||
if (escaping) {
|
||||
valueStart = i - 1;
|
||||
escaping = false;
|
||||
}
|
||||
// Invalid unescaped quoted character (malformed)
|
||||
if (QDTEXT[code] !== 1)
|
||||
return;
|
||||
}
|
||||
|
||||
// No end quote (malformed)
|
||||
if (i === str.length)
|
||||
return;
|
||||
|
||||
++i; // Skip over double quote
|
||||
} else {
|
||||
valueStart = i;
|
||||
// Parse unquoted value
|
||||
for (; i < str.length; ++i) {
|
||||
const code = str.charCodeAt(i);
|
||||
if (TOKEN[code] !== 1) {
|
||||
// No value (malformed)
|
||||
if (i === valueStart)
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
value = str.slice(valueStart, i);
|
||||
}
|
||||
|
||||
name = name.toLowerCase();
|
||||
if (params[name] === undefined)
|
||||
params[name] = value;
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
function parseDisposition(str, defDecoder) {
|
||||
if (str.length === 0)
|
||||
return;
|
||||
|
||||
const params = Object.create(null);
|
||||
let i = 0;
|
||||
|
||||
for (; i < str.length; ++i) {
|
||||
const code = str.charCodeAt(i);
|
||||
if (TOKEN[code] !== 1) {
|
||||
if (parseDispositionParams(str, i, params, defDecoder) === undefined)
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const type = str.slice(0, i).toLowerCase();
|
||||
|
||||
return { type, params };
|
||||
}
|
||||
|
||||
function parseDispositionParams(str, i, params, defDecoder) {
|
||||
while (i < str.length) {
|
||||
// Consume whitespace
|
||||
for (; i < str.length; ++i) {
|
||||
const code = str.charCodeAt(i);
|
||||
if (code !== 32/* ' ' */ && code !== 9/* '\t' */)
|
||||
break;
|
||||
}
|
||||
|
||||
// Ended on whitespace
|
||||
if (i === str.length)
|
||||
break;
|
||||
|
||||
// Check for malformed parameter
|
||||
if (str.charCodeAt(i++) !== 59/* ';' */)
|
||||
return;
|
||||
|
||||
// Consume whitespace
|
||||
for (; i < str.length; ++i) {
|
||||
const code = str.charCodeAt(i);
|
||||
if (code !== 32/* ' ' */ && code !== 9/* '\t' */)
|
||||
break;
|
||||
}
|
||||
|
||||
// Ended on whitespace (malformed)
|
||||
if (i === str.length)
|
||||
return;
|
||||
|
||||
let name;
|
||||
const nameStart = i;
|
||||
// Parse parameter name
|
||||
for (; i < str.length; ++i) {
|
||||
const code = str.charCodeAt(i);
|
||||
if (TOKEN[code] !== 1) {
|
||||
if (code === 61/* '=' */)
|
||||
break;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// No value (malformed)
|
||||
if (i === str.length)
|
||||
return;
|
||||
|
||||
let value = '';
|
||||
let valueStart;
|
||||
let charset;
|
||||
//~ let lang;
|
||||
name = str.slice(nameStart, i);
|
||||
if (name.charCodeAt(name.length - 1) === 42/* '*' */) {
|
||||
// Extended value
|
||||
|
||||
const charsetStart = ++i;
|
||||
// Parse charset name
|
||||
for (; i < str.length; ++i) {
|
||||
const code = str.charCodeAt(i);
|
||||
if (CHARSET[code] !== 1) {
|
||||
if (code !== 39/* '\'' */)
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Incomplete charset (malformed)
|
||||
if (i === str.length)
|
||||
return;
|
||||
|
||||
charset = str.slice(charsetStart, i);
|
||||
++i; // Skip over the '\''
|
||||
|
||||
//~ const langStart = ++i;
|
||||
// Parse language name
|
||||
for (; i < str.length; ++i) {
|
||||
const code = str.charCodeAt(i);
|
||||
if (code === 39/* '\'' */)
|
||||
break;
|
||||
}
|
||||
|
||||
// Incomplete language (malformed)
|
||||
if (i === str.length)
|
||||
return;
|
||||
|
||||
//~ lang = str.slice(langStart, i);
|
||||
++i; // Skip over the '\''
|
||||
|
||||
// No value (malformed)
|
||||
if (i === str.length)
|
||||
return;
|
||||
|
||||
valueStart = i;
|
||||
|
||||
let encode = 0;
|
||||
// Parse value
|
||||
for (; i < str.length; ++i) {
|
||||
const code = str.charCodeAt(i);
|
||||
if (EXTENDED_VALUE[code] !== 1) {
|
||||
if (code === 37/* '%' */) {
|
||||
let hexUpper;
|
||||
let hexLower;
|
||||
if (i + 2 < str.length
|
||||
&& (hexUpper = HEX_VALUES[str.charCodeAt(i + 1)]) !== -1
|
||||
&& (hexLower = HEX_VALUES[str.charCodeAt(i + 2)]) !== -1) {
|
||||
const byteVal = (hexUpper << 4) + hexLower;
|
||||
value += str.slice(valueStart, i);
|
||||
value += String.fromCharCode(byteVal);
|
||||
i += 2;
|
||||
valueStart = i + 1;
|
||||
if (byteVal >= 128)
|
||||
encode = 2;
|
||||
else if (encode === 0)
|
||||
encode = 1;
|
||||
continue;
|
||||
}
|
||||
// '%' disallowed in non-percent encoded contexts (malformed)
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
value += str.slice(valueStart, i);
|
||||
value = convertToUTF8(value, charset, encode);
|
||||
if (value === undefined)
|
||||
return;
|
||||
} else {
|
||||
// Non-extended value
|
||||
|
||||
++i; // Skip over '='
|
||||
|
||||
// No value (malformed)
|
||||
if (i === str.length)
|
||||
return;
|
||||
|
||||
if (str.charCodeAt(i) === 34/* '"' */) {
|
||||
valueStart = ++i;
|
||||
let escaping = false;
|
||||
// Parse quoted value
|
||||
for (; i < str.length; ++i) {
|
||||
const code = str.charCodeAt(i);
|
||||
if (code === 92/* '\\' */) {
|
||||
if (escaping) {
|
||||
valueStart = i;
|
||||
escaping = false;
|
||||
} else {
|
||||
value += str.slice(valueStart, i);
|
||||
escaping = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (code === 34/* '"' */) {
|
||||
if (escaping) {
|
||||
valueStart = i;
|
||||
escaping = false;
|
||||
continue;
|
||||
}
|
||||
value += str.slice(valueStart, i);
|
||||
break;
|
||||
}
|
||||
if (escaping) {
|
||||
valueStart = i - 1;
|
||||
escaping = false;
|
||||
}
|
||||
// Invalid unescaped quoted character (malformed)
|
||||
if (QDTEXT[code] !== 1)
|
||||
return;
|
||||
}
|
||||
|
||||
// No end quote (malformed)
|
||||
if (i === str.length)
|
||||
return;
|
||||
|
||||
++i; // Skip over double quote
|
||||
} else {
|
||||
valueStart = i;
|
||||
// Parse unquoted value
|
||||
for (; i < str.length; ++i) {
|
||||
const code = str.charCodeAt(i);
|
||||
if (TOKEN[code] !== 1) {
|
||||
// No value (malformed)
|
||||
if (i === valueStart)
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
value = str.slice(valueStart, i);
|
||||
}
|
||||
|
||||
value = defDecoder(value, 2);
|
||||
if (value === undefined)
|
||||
return;
|
||||
}
|
||||
|
||||
name = name.toLowerCase();
|
||||
if (params[name] === undefined)
|
||||
params[name] = value;
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
function getDecoder(charset) {
|
||||
let lc;
|
||||
while (true) {
|
||||
switch (charset) {
|
||||
case 'utf-8':
|
||||
case 'utf8':
|
||||
return decoders.utf8;
|
||||
case 'latin1':
|
||||
case 'ascii': // TODO: Make these a separate, strict decoder?
|
||||
case 'us-ascii':
|
||||
case 'iso-8859-1':
|
||||
case 'iso8859-1':
|
||||
case 'iso88591':
|
||||
case 'iso_8859-1':
|
||||
case 'windows-1252':
|
||||
case 'iso_8859-1:1987':
|
||||
case 'cp1252':
|
||||
case 'x-cp1252':
|
||||
return decoders.latin1;
|
||||
case 'utf16le':
|
||||
case 'utf-16le':
|
||||
case 'ucs2':
|
||||
case 'ucs-2':
|
||||
return decoders.utf16le;
|
||||
case 'base64':
|
||||
return decoders.base64;
|
||||
default:
|
||||
if (lc === undefined) {
|
||||
lc = true;
|
||||
charset = charset.toLowerCase();
|
||||
continue;
|
||||
}
|
||||
return decoders.other.bind(charset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const decoders = {
|
||||
utf8: (data, hint) => {
|
||||
if (data.length === 0)
|
||||
return '';
|
||||
if (typeof data === 'string') {
|
||||
// If `data` never had any percent-encoded bytes or never had any that
|
||||
// were outside of the ASCII range, then we can safely just return the
|
||||
// input since UTF-8 is ASCII compatible
|
||||
if (hint < 2)
|
||||
return data;
|
||||
|
||||
data = Buffer.from(data, 'latin1');
|
||||
}
|
||||
return data.utf8Slice(0, data.length);
|
||||
},
|
||||
|
||||
latin1: (data, hint) => {
|
||||
if (data.length === 0)
|
||||
return '';
|
||||
if (typeof data === 'string')
|
||||
return data;
|
||||
return data.latin1Slice(0, data.length);
|
||||
},
|
||||
|
||||
utf16le: (data, hint) => {
|
||||
if (data.length === 0)
|
||||
return '';
|
||||
if (typeof data === 'string')
|
||||
data = Buffer.from(data, 'latin1');
|
||||
return data.ucs2Slice(0, data.length);
|
||||
},
|
||||
|
||||
base64: (data, hint) => {
|
||||
if (data.length === 0)
|
||||
return '';
|
||||
if (typeof data === 'string')
|
||||
data = Buffer.from(data, 'latin1');
|
||||
return data.base64Slice(0, data.length);
|
||||
},
|
||||
|
||||
other: (data, hint) => {
|
||||
if (data.length === 0)
|
||||
return '';
|
||||
if (typeof data === 'string')
|
||||
data = Buffer.from(data, 'latin1');
|
||||
try {
|
||||
const decoder = new TextDecoder(this);
|
||||
return decoder.decode(data);
|
||||
} catch {}
|
||||
},
|
||||
};
|
||||
|
||||
function convertToUTF8(data, charset, hint) {
|
||||
const decode = getDecoder(charset);
|
||||
if (decode)
|
||||
return decode(data, hint);
|
||||
}
|
||||
|
||||
function basename(path) {
|
||||
if (typeof path !== 'string')
|
||||
return '';
|
||||
for (let i = path.length - 1; i >= 0; --i) {
|
||||
switch (path.charCodeAt(i)) {
|
||||
case 0x2F: // '/'
|
||||
case 0x5C: // '\'
|
||||
path = path.slice(i + 1);
|
||||
return (path === '..' || path === '.' ? '' : path);
|
||||
}
|
||||
}
|
||||
return (path === '..' || path === '.' ? '' : path);
|
||||
}
|
||||
|
||||
const TOKEN = [
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
|
||||
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
|
||||
const QDTEXT = [
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
];
|
||||
|
||||
const CHARSET = [
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
|
||||
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
|
||||
const EXTENDED_VALUE = [
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
|
||||
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
|
||||
/* eslint-disable no-multi-spaces */
|
||||
const HEX_VALUES = [
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
|
||||
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
];
|
||||
/* eslint-enable no-multi-spaces */
|
||||
|
||||
module.exports = {
|
||||
basename,
|
||||
convertToUTF8,
|
||||
getDecoder,
|
||||
parseContentType,
|
||||
parseDisposition,
|
||||
};
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
{ "name": "busboy",
|
||||
"version": "1.6.0",
|
||||
"author": "Brian White <mscdex@mscdex.net>",
|
||||
"description": "A streaming parser for HTML form data for node.js",
|
||||
"main": "./lib/index.js",
|
||||
"dependencies": {
|
||||
"streamsearch": "^1.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@mscdex/eslint-config": "^1.1.0",
|
||||
"eslint": "^7.32.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test/test.js",
|
||||
"lint": "eslint --cache --report-unused-disable-directives --ext=.js .eslintrc.js lib test bench",
|
||||
"lint:fix": "npm run lint -- --fix"
|
||||
},
|
||||
"engines": { "node": ">=10.16.0" },
|
||||
"keywords": [ "uploads", "forms", "multipart", "form-data" ],
|
||||
"licenses": [ { "type": "MIT", "url": "http://github.com/mscdex/busboy/raw/master/LICENSE" } ],
|
||||
"repository": { "type": "git", "url": "http://github.com/mscdex/busboy.git" }
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const { inspect } = require('util');
|
||||
|
||||
const mustCallChecks = [];
|
||||
|
||||
function noop() {}
|
||||
|
||||
function runCallChecks(exitCode) {
|
||||
if (exitCode !== 0) return;
|
||||
|
||||
const failed = mustCallChecks.filter((context) => {
|
||||
if ('minimum' in context) {
|
||||
context.messageSegment = `at least ${context.minimum}`;
|
||||
return context.actual < context.minimum;
|
||||
}
|
||||
context.messageSegment = `exactly ${context.exact}`;
|
||||
return context.actual !== context.exact;
|
||||
});
|
||||
|
||||
failed.forEach((context) => {
|
||||
console.error('Mismatched %s function calls. Expected %s, actual %d.',
|
||||
context.name,
|
||||
context.messageSegment,
|
||||
context.actual);
|
||||
console.error(context.stack.split('\n').slice(2).join('\n'));
|
||||
});
|
||||
|
||||
if (failed.length)
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function mustCall(fn, exact) {
|
||||
return _mustCallInner(fn, exact, 'exact');
|
||||
}
|
||||
|
||||
function mustCallAtLeast(fn, minimum) {
|
||||
return _mustCallInner(fn, minimum, 'minimum');
|
||||
}
|
||||
|
||||
function _mustCallInner(fn, criteria = 1, field) {
|
||||
if (process._exiting)
|
||||
throw new Error('Cannot use common.mustCall*() in process exit handler');
|
||||
|
||||
if (typeof fn === 'number') {
|
||||
criteria = fn;
|
||||
fn = noop;
|
||||
} else if (fn === undefined) {
|
||||
fn = noop;
|
||||
}
|
||||
|
||||
if (typeof criteria !== 'number')
|
||||
throw new TypeError(`Invalid ${field} value: ${criteria}`);
|
||||
|
||||
const context = {
|
||||
[field]: criteria,
|
||||
actual: 0,
|
||||
stack: inspect(new Error()),
|
||||
name: fn.name || '<anonymous>'
|
||||
};
|
||||
|
||||
// Add the exit listener only once to avoid listener leak warnings
|
||||
if (mustCallChecks.length === 0)
|
||||
process.on('exit', runCallChecks);
|
||||
|
||||
mustCallChecks.push(context);
|
||||
|
||||
function wrapped(...args) {
|
||||
++context.actual;
|
||||
return fn.call(this, ...args);
|
||||
}
|
||||
// TODO: remove origFn?
|
||||
wrapped.origFn = fn;
|
||||
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
function getCallSite(top) {
|
||||
const originalStackFormatter = Error.prepareStackTrace;
|
||||
Error.prepareStackTrace = (err, stack) =>
|
||||
`${stack[0].getFileName()}:${stack[0].getLineNumber()}`;
|
||||
const err = new Error();
|
||||
Error.captureStackTrace(err, top);
|
||||
// With the V8 Error API, the stack is not formatted until it is accessed
|
||||
// eslint-disable-next-line no-unused-expressions
|
||||
err.stack;
|
||||
Error.prepareStackTrace = originalStackFormatter;
|
||||
return err.stack;
|
||||
}
|
||||
|
||||
function mustNotCall(msg) {
|
||||
const callSite = getCallSite(mustNotCall);
|
||||
return function mustNotCall(...args) {
|
||||
args = args.map(inspect).join(', ');
|
||||
const argsInfo = (args.length > 0
|
||||
? `\ncalled with arguments: ${args}`
|
||||
: '');
|
||||
assert.fail(
|
||||
`${msg || 'function should not have been called'} at ${callSite}`
|
||||
+ argsInfo);
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
mustCall,
|
||||
mustCallAtLeast,
|
||||
mustNotCall,
|
||||
};
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const { inspect } = require('util');
|
||||
|
||||
const { mustCall } = require(`${__dirname}/common.js`);
|
||||
|
||||
const busboy = require('..');
|
||||
|
||||
const input = Buffer.from([
|
||||
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
|
||||
'Content-Disposition: form-data; '
|
||||
+ 'name="upload_file_0"; filename="テスト.dat"',
|
||||
'Content-Type: application/octet-stream',
|
||||
'',
|
||||
'A'.repeat(1023),
|
||||
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k--'
|
||||
].join('\r\n'));
|
||||
const boundary = '---------------------------paZqsnEHRufoShdX6fh0lUhXBP4k';
|
||||
const expected = [
|
||||
{ type: 'file',
|
||||
name: 'upload_file_0',
|
||||
data: Buffer.from('A'.repeat(1023)),
|
||||
info: {
|
||||
filename: 'テスト.dat',
|
||||
encoding: '7bit',
|
||||
mimeType: 'application/octet-stream',
|
||||
},
|
||||
limited: false,
|
||||
},
|
||||
];
|
||||
const bb = busboy({
|
||||
defParamCharset: 'utf8',
|
||||
headers: {
|
||||
'content-type': `multipart/form-data; boundary=${boundary}`,
|
||||
}
|
||||
});
|
||||
const results = [];
|
||||
|
||||
bb.on('field', (name, val, info) => {
|
||||
results.push({ type: 'field', name, val, info });
|
||||
});
|
||||
|
||||
bb.on('file', (name, stream, info) => {
|
||||
const data = [];
|
||||
let nb = 0;
|
||||
const file = {
|
||||
type: 'file',
|
||||
name,
|
||||
data: null,
|
||||
info,
|
||||
limited: false,
|
||||
};
|
||||
results.push(file);
|
||||
stream.on('data', (d) => {
|
||||
data.push(d);
|
||||
nb += d.length;
|
||||
}).on('limit', () => {
|
||||
file.limited = true;
|
||||
}).on('close', () => {
|
||||
file.data = Buffer.concat(data, nb);
|
||||
assert.strictEqual(stream.truncated, file.limited);
|
||||
}).once('error', (err) => {
|
||||
file.err = err.message;
|
||||
});
|
||||
});
|
||||
|
||||
bb.on('error', (err) => {
|
||||
results.push({ error: err.message });
|
||||
});
|
||||
|
||||
bb.on('partsLimit', () => {
|
||||
results.push('partsLimit');
|
||||
});
|
||||
|
||||
bb.on('filesLimit', () => {
|
||||
results.push('filesLimit');
|
||||
});
|
||||
|
||||
bb.on('fieldsLimit', () => {
|
||||
results.push('fieldsLimit');
|
||||
});
|
||||
|
||||
bb.on('close', mustCall(() => {
|
||||
assert.deepStrictEqual(
|
||||
results,
|
||||
expected,
|
||||
'Results mismatch.\n'
|
||||
+ `Parsed: ${inspect(results)}\n`
|
||||
+ `Expected: ${inspect(expected)}`
|
||||
);
|
||||
}));
|
||||
|
||||
bb.end(input);
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const { randomFillSync } = require('crypto');
|
||||
const { inspect } = require('util');
|
||||
|
||||
const busboy = require('..');
|
||||
|
||||
const { mustCall } = require('./common.js');
|
||||
|
||||
const BOUNDARY = 'u2KxIV5yF1y+xUspOQCCZopaVgeV6Jxihv35XQJmuTx8X3sh';
|
||||
|
||||
function formDataSection(key, value) {
|
||||
return Buffer.from(
|
||||
`\r\n--${BOUNDARY}`
|
||||
+ `\r\nContent-Disposition: form-data; name="${key}"`
|
||||
+ `\r\n\r\n${value}`
|
||||
);
|
||||
}
|
||||
|
||||
function formDataFile(key, filename, contentType) {
|
||||
const buf = Buffer.allocUnsafe(100000);
|
||||
return Buffer.concat([
|
||||
Buffer.from(`\r\n--${BOUNDARY}\r\n`),
|
||||
Buffer.from(`Content-Disposition: form-data; name="${key}"`
|
||||
+ `; filename="${filename}"\r\n`),
|
||||
Buffer.from(`Content-Type: ${contentType}\r\n\r\n`),
|
||||
randomFillSync(buf)
|
||||
]);
|
||||
}
|
||||
|
||||
const reqChunks = [
|
||||
Buffer.concat([
|
||||
formDataFile('file', 'file.bin', 'application/octet-stream'),
|
||||
formDataSection('foo', 'foo value'),
|
||||
]),
|
||||
formDataSection('bar', 'bar value'),
|
||||
Buffer.from(`\r\n--${BOUNDARY}--\r\n`)
|
||||
];
|
||||
const bb = busboy({
|
||||
headers: {
|
||||
'content-type': `multipart/form-data; boundary=${BOUNDARY}`
|
||||
}
|
||||
});
|
||||
const expected = [
|
||||
{ type: 'file',
|
||||
name: 'file',
|
||||
info: {
|
||||
filename: 'file.bin',
|
||||
encoding: '7bit',
|
||||
mimeType: 'application/octet-stream',
|
||||
},
|
||||
},
|
||||
{ type: 'field',
|
||||
name: 'foo',
|
||||
val: 'foo value',
|
||||
info: {
|
||||
nameTruncated: false,
|
||||
valueTruncated: false,
|
||||
encoding: '7bit',
|
||||
mimeType: 'text/plain',
|
||||
},
|
||||
},
|
||||
{ type: 'field',
|
||||
name: 'bar',
|
||||
val: 'bar value',
|
||||
info: {
|
||||
nameTruncated: false,
|
||||
valueTruncated: false,
|
||||
encoding: '7bit',
|
||||
mimeType: 'text/plain',
|
||||
},
|
||||
},
|
||||
];
|
||||
const results = [];
|
||||
|
||||
bb.on('field', (name, val, info) => {
|
||||
results.push({ type: 'field', name, val, info });
|
||||
});
|
||||
|
||||
bb.on('file', (name, stream, info) => {
|
||||
results.push({ type: 'file', name, info });
|
||||
// Simulate a pipe where the destination is pausing (perhaps due to waiting
|
||||
// for file system write to finish)
|
||||
setTimeout(() => {
|
||||
stream.resume();
|
||||
}, 10);
|
||||
});
|
||||
|
||||
bb.on('close', mustCall(() => {
|
||||
assert.deepStrictEqual(
|
||||
results,
|
||||
expected,
|
||||
'Results mismatch.\n'
|
||||
+ `Parsed: ${inspect(results)}\n`
|
||||
+ `Expected: ${inspect(expected)}`
|
||||
);
|
||||
}));
|
||||
|
||||
for (const chunk of reqChunks)
|
||||
bb.write(chunk);
|
||||
bb.end();
|
||||
+1053
File diff suppressed because it is too large
Load Diff
+488
@@ -0,0 +1,488 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const { transcode } = require('buffer');
|
||||
const { inspect } = require('util');
|
||||
|
||||
const busboy = require('..');
|
||||
|
||||
const active = new Map();
|
||||
|
||||
const tests = [
|
||||
{ source: ['foo'],
|
||||
expected: [
|
||||
['foo',
|
||||
'',
|
||||
{ nameTruncated: false,
|
||||
valueTruncated: false,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
],
|
||||
what: 'Unassigned value'
|
||||
},
|
||||
{ source: ['foo=bar'],
|
||||
expected: [
|
||||
['foo',
|
||||
'bar',
|
||||
{ nameTruncated: false,
|
||||
valueTruncated: false,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
],
|
||||
what: 'Assigned value'
|
||||
},
|
||||
{ source: ['foo&bar=baz'],
|
||||
expected: [
|
||||
['foo',
|
||||
'',
|
||||
{ nameTruncated: false,
|
||||
valueTruncated: false,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
['bar',
|
||||
'baz',
|
||||
{ nameTruncated: false,
|
||||
valueTruncated: false,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
],
|
||||
what: 'Unassigned and assigned value'
|
||||
},
|
||||
{ source: ['foo=bar&baz'],
|
||||
expected: [
|
||||
['foo',
|
||||
'bar',
|
||||
{ nameTruncated: false,
|
||||
valueTruncated: false,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
['baz',
|
||||
'',
|
||||
{ nameTruncated: false,
|
||||
valueTruncated: false,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
],
|
||||
what: 'Assigned and unassigned value'
|
||||
},
|
||||
{ source: ['foo=bar&baz=bla'],
|
||||
expected: [
|
||||
['foo',
|
||||
'bar',
|
||||
{ nameTruncated: false,
|
||||
valueTruncated: false,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
['baz',
|
||||
'bla',
|
||||
{ nameTruncated: false,
|
||||
valueTruncated: false,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
],
|
||||
what: 'Two assigned values'
|
||||
},
|
||||
{ source: ['foo&bar'],
|
||||
expected: [
|
||||
['foo',
|
||||
'',
|
||||
{ nameTruncated: false,
|
||||
valueTruncated: false,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
['bar',
|
||||
'',
|
||||
{ nameTruncated: false,
|
||||
valueTruncated: false,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
],
|
||||
what: 'Two unassigned values'
|
||||
},
|
||||
{ source: ['foo&bar&'],
|
||||
expected: [
|
||||
['foo',
|
||||
'',
|
||||
{ nameTruncated: false,
|
||||
valueTruncated: false,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
['bar',
|
||||
'',
|
||||
{ nameTruncated: false,
|
||||
valueTruncated: false,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
],
|
||||
what: 'Two unassigned values and ampersand'
|
||||
},
|
||||
{ source: ['foo+1=bar+baz%2Bquux'],
|
||||
expected: [
|
||||
['foo 1',
|
||||
'bar baz+quux',
|
||||
{ nameTruncated: false,
|
||||
valueTruncated: false,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
],
|
||||
what: 'Assigned key and value with (plus) space'
|
||||
},
|
||||
{ source: ['foo=bar%20baz%21'],
|
||||
expected: [
|
||||
['foo',
|
||||
'bar baz!',
|
||||
{ nameTruncated: false,
|
||||
valueTruncated: false,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
],
|
||||
what: 'Assigned value with encoded bytes'
|
||||
},
|
||||
{ source: ['foo%20bar=baz%20bla%21'],
|
||||
expected: [
|
||||
['foo bar',
|
||||
'baz bla!',
|
||||
{ nameTruncated: false,
|
||||
valueTruncated: false,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
],
|
||||
what: 'Assigned value with encoded bytes #2'
|
||||
},
|
||||
{ source: ['foo=bar%20baz%21&num=1000'],
|
||||
expected: [
|
||||
['foo',
|
||||
'bar baz!',
|
||||
{ nameTruncated: false,
|
||||
valueTruncated: false,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
['num',
|
||||
'1000',
|
||||
{ nameTruncated: false,
|
||||
valueTruncated: false,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
],
|
||||
what: 'Two assigned values, one with encoded bytes'
|
||||
},
|
||||
{ source: [
|
||||
Array.from(transcode(Buffer.from('foo'), 'utf8', 'utf16le')).map(
|
||||
(n) => `%${n.toString(16).padStart(2, '0')}`
|
||||
).join(''),
|
||||
'=',
|
||||
Array.from(transcode(Buffer.from('😀!'), 'utf8', 'utf16le')).map(
|
||||
(n) => `%${n.toString(16).padStart(2, '0')}`
|
||||
).join(''),
|
||||
],
|
||||
expected: [
|
||||
['foo',
|
||||
'😀!',
|
||||
{ nameTruncated: false,
|
||||
valueTruncated: false,
|
||||
encoding: 'UTF-16LE',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
],
|
||||
charset: 'UTF-16LE',
|
||||
what: 'Encoded value with multi-byte charset'
|
||||
},
|
||||
{ source: [
|
||||
'foo=<',
|
||||
Array.from(transcode(Buffer.from('©:^þ'), 'utf8', 'latin1')).map(
|
||||
(n) => `%${n.toString(16).padStart(2, '0')}`
|
||||
).join(''),
|
||||
],
|
||||
expected: [
|
||||
['foo',
|
||||
'<©:^þ',
|
||||
{ nameTruncated: false,
|
||||
valueTruncated: false,
|
||||
encoding: 'ISO-8859-1',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
],
|
||||
charset: 'ISO-8859-1',
|
||||
what: 'Encoded value with single-byte, ASCII-compatible, non-UTF8 charset'
|
||||
},
|
||||
{ source: ['foo=bar&baz=bla'],
|
||||
expected: [],
|
||||
what: 'Limits: zero fields',
|
||||
limits: { fields: 0 }
|
||||
},
|
||||
{ source: ['foo=bar&baz=bla'],
|
||||
expected: [
|
||||
['foo',
|
||||
'bar',
|
||||
{ nameTruncated: false,
|
||||
valueTruncated: false,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
],
|
||||
what: 'Limits: one field',
|
||||
limits: { fields: 1 }
|
||||
},
|
||||
{ source: ['foo=bar&baz=bla'],
|
||||
expected: [
|
||||
['foo',
|
||||
'bar',
|
||||
{ nameTruncated: false,
|
||||
valueTruncated: false,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
['baz',
|
||||
'bla',
|
||||
{ nameTruncated: false,
|
||||
valueTruncated: false,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
],
|
||||
what: 'Limits: field part lengths match limits',
|
||||
limits: { fieldNameSize: 3, fieldSize: 3 }
|
||||
},
|
||||
{ source: ['foo=bar&baz=bla'],
|
||||
expected: [
|
||||
['fo',
|
||||
'bar',
|
||||
{ nameTruncated: true,
|
||||
valueTruncated: false,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
['ba',
|
||||
'bla',
|
||||
{ nameTruncated: true,
|
||||
valueTruncated: false,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
],
|
||||
what: 'Limits: truncated field name',
|
||||
limits: { fieldNameSize: 2 }
|
||||
},
|
||||
{ source: ['foo=bar&baz=bla'],
|
||||
expected: [
|
||||
['foo',
|
||||
'ba',
|
||||
{ nameTruncated: false,
|
||||
valueTruncated: true,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
['baz',
|
||||
'bl',
|
||||
{ nameTruncated: false,
|
||||
valueTruncated: true,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
],
|
||||
what: 'Limits: truncated field value',
|
||||
limits: { fieldSize: 2 }
|
||||
},
|
||||
{ source: ['foo=bar&baz=bla'],
|
||||
expected: [
|
||||
['fo',
|
||||
'ba',
|
||||
{ nameTruncated: true,
|
||||
valueTruncated: true,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
['ba',
|
||||
'bl',
|
||||
{ nameTruncated: true,
|
||||
valueTruncated: true,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
],
|
||||
what: 'Limits: truncated field name and value',
|
||||
limits: { fieldNameSize: 2, fieldSize: 2 }
|
||||
},
|
||||
{ source: ['foo=bar&baz=bla'],
|
||||
expected: [
|
||||
['fo',
|
||||
'',
|
||||
{ nameTruncated: true,
|
||||
valueTruncated: true,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
['ba',
|
||||
'',
|
||||
{ nameTruncated: true,
|
||||
valueTruncated: true,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
],
|
||||
what: 'Limits: truncated field name and zero value limit',
|
||||
limits: { fieldNameSize: 2, fieldSize: 0 }
|
||||
},
|
||||
{ source: ['foo=bar&baz=bla'],
|
||||
expected: [
|
||||
['',
|
||||
'',
|
||||
{ nameTruncated: true,
|
||||
valueTruncated: true,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
['',
|
||||
'',
|
||||
{ nameTruncated: true,
|
||||
valueTruncated: true,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
],
|
||||
what: 'Limits: truncated zero field name and zero value limit',
|
||||
limits: { fieldNameSize: 0, fieldSize: 0 }
|
||||
},
|
||||
{ source: ['&'],
|
||||
expected: [],
|
||||
what: 'Ampersand'
|
||||
},
|
||||
{ source: ['&&&&&'],
|
||||
expected: [],
|
||||
what: 'Many ampersands'
|
||||
},
|
||||
{ source: ['='],
|
||||
expected: [
|
||||
['',
|
||||
'',
|
||||
{ nameTruncated: false,
|
||||
valueTruncated: false,
|
||||
encoding: 'utf-8',
|
||||
mimeType: 'text/plain' },
|
||||
],
|
||||
],
|
||||
what: 'Assigned value, empty name and value'
|
||||
},
|
||||
{ source: [''],
|
||||
expected: [],
|
||||
what: 'Nothing'
|
||||
},
|
||||
];
|
||||
|
||||
for (const test of tests) {
|
||||
active.set(test, 1);
|
||||
|
||||
const { what } = test;
|
||||
const charset = test.charset || 'utf-8';
|
||||
const bb = busboy({
|
||||
limits: test.limits,
|
||||
headers: {
|
||||
'content-type': `application/x-www-form-urlencoded; charset=${charset}`,
|
||||
},
|
||||
});
|
||||
const results = [];
|
||||
|
||||
bb.on('field', (key, val, info) => {
|
||||
results.push([key, val, info]);
|
||||
});
|
||||
|
||||
bb.on('file', () => {
|
||||
throw new Error(`[${what}] Unexpected file`);
|
||||
});
|
||||
|
||||
bb.on('close', () => {
|
||||
active.delete(test);
|
||||
|
||||
assert.deepStrictEqual(
|
||||
results,
|
||||
test.expected,
|
||||
`[${what}] Results mismatch.\n`
|
||||
+ `Parsed: ${inspect(results)}\n`
|
||||
+ `Expected: ${inspect(test.expected)}`
|
||||
);
|
||||
});
|
||||
|
||||
for (const src of test.source) {
|
||||
const buf = (typeof src === 'string' ? Buffer.from(src, 'utf8') : src);
|
||||
bb.write(buf);
|
||||
}
|
||||
bb.end();
|
||||
}
|
||||
|
||||
// Byte-by-byte versions
|
||||
for (let test of tests) {
|
||||
test = { ...test };
|
||||
test.what += ' (byte-by-byte)';
|
||||
active.set(test, 1);
|
||||
|
||||
const { what } = test;
|
||||
const charset = test.charset || 'utf-8';
|
||||
const bb = busboy({
|
||||
limits: test.limits,
|
||||
headers: {
|
||||
'content-type': `application/x-www-form-urlencoded; charset="${charset}"`,
|
||||
},
|
||||
});
|
||||
const results = [];
|
||||
|
||||
bb.on('field', (key, val, info) => {
|
||||
results.push([key, val, info]);
|
||||
});
|
||||
|
||||
bb.on('file', () => {
|
||||
throw new Error(`[${what}] Unexpected file`);
|
||||
});
|
||||
|
||||
bb.on('close', () => {
|
||||
active.delete(test);
|
||||
|
||||
assert.deepStrictEqual(
|
||||
results,
|
||||
test.expected,
|
||||
`[${what}] Results mismatch.\n`
|
||||
+ `Parsed: ${inspect(results)}\n`
|
||||
+ `Expected: ${inspect(test.expected)}`
|
||||
);
|
||||
});
|
||||
|
||||
for (const src of test.source) {
|
||||
const buf = (typeof src === 'string' ? Buffer.from(src, 'utf8') : src);
|
||||
for (let i = 0; i < buf.length; ++i)
|
||||
bb.write(buf.slice(i, i + 1));
|
||||
}
|
||||
bb.end();
|
||||
}
|
||||
|
||||
{
|
||||
let exception = false;
|
||||
process.once('uncaughtException', (ex) => {
|
||||
exception = true;
|
||||
throw ex;
|
||||
});
|
||||
process.on('exit', () => {
|
||||
if (exception || active.size === 0)
|
||||
return;
|
||||
process.exitCode = 1;
|
||||
console.error('==========================');
|
||||
console.error(`${active.size} test(s) did not finish:`);
|
||||
console.error('==========================');
|
||||
console.error(Array.from(active.keys()).map((v) => v.what).join('\n'));
|
||||
});
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
const { spawnSync } = require('child_process');
|
||||
const { readdirSync } = require('fs');
|
||||
const { join } = require('path');
|
||||
|
||||
const files = readdirSync(__dirname).sort();
|
||||
for (const filename of files) {
|
||||
if (filename.startsWith('test-')) {
|
||||
const path = join(__dirname, filename);
|
||||
console.log(`> Running ${filename} ...`);
|
||||
const result = spawnSync(`${process.argv0} ${path}`, {
|
||||
shell: true,
|
||||
stdio: 'inherit',
|
||||
windowsHide: true
|
||||
});
|
||||
if (result.status !== 0)
|
||||
process.exitCode = 1;
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2013 Max Ogden
|
||||
|
||||
Permission is hereby granted, free of charge,
|
||||
to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to
|
||||
deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify,
|
||||
merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom
|
||||
the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
|
||||
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
var Writable = require('readable-stream').Writable
|
||||
var inherits = require('inherits')
|
||||
var bufferFrom = require('buffer-from')
|
||||
|
||||
if (typeof Uint8Array === 'undefined') {
|
||||
var U8 = require('typedarray').Uint8Array
|
||||
} else {
|
||||
var U8 = Uint8Array
|
||||
}
|
||||
|
||||
function ConcatStream(opts, cb) {
|
||||
if (!(this instanceof ConcatStream)) return new ConcatStream(opts, cb)
|
||||
|
||||
if (typeof opts === 'function') {
|
||||
cb = opts
|
||||
opts = {}
|
||||
}
|
||||
if (!opts) opts = {}
|
||||
|
||||
var encoding = opts.encoding
|
||||
var shouldInferEncoding = false
|
||||
|
||||
if (!encoding) {
|
||||
shouldInferEncoding = true
|
||||
} else {
|
||||
encoding = String(encoding).toLowerCase()
|
||||
if (encoding === 'u8' || encoding === 'uint8') {
|
||||
encoding = 'uint8array'
|
||||
}
|
||||
}
|
||||
|
||||
Writable.call(this, { objectMode: true })
|
||||
|
||||
this.encoding = encoding
|
||||
this.shouldInferEncoding = shouldInferEncoding
|
||||
|
||||
if (cb) this.on('finish', function () { cb(this.getBody()) })
|
||||
this.body = []
|
||||
}
|
||||
|
||||
module.exports = ConcatStream
|
||||
inherits(ConcatStream, Writable)
|
||||
|
||||
ConcatStream.prototype._write = function(chunk, enc, next) {
|
||||
this.body.push(chunk)
|
||||
next()
|
||||
}
|
||||
|
||||
ConcatStream.prototype.inferEncoding = function (buff) {
|
||||
var firstBuffer = buff === undefined ? this.body[0] : buff;
|
||||
if (Buffer.isBuffer(firstBuffer)) return 'buffer'
|
||||
if (typeof Uint8Array !== 'undefined' && firstBuffer instanceof Uint8Array) return 'uint8array'
|
||||
if (Array.isArray(firstBuffer)) return 'array'
|
||||
if (typeof firstBuffer === 'string') return 'string'
|
||||
if (Object.prototype.toString.call(firstBuffer) === "[object Object]") return 'object'
|
||||
return 'buffer'
|
||||
}
|
||||
|
||||
ConcatStream.prototype.getBody = function () {
|
||||
if (!this.encoding && this.body.length === 0) return []
|
||||
if (this.shouldInferEncoding) this.encoding = this.inferEncoding()
|
||||
if (this.encoding === 'array') return arrayConcat(this.body)
|
||||
if (this.encoding === 'string') return stringConcat(this.body)
|
||||
if (this.encoding === 'buffer') return bufferConcat(this.body)
|
||||
if (this.encoding === 'uint8array') return u8Concat(this.body)
|
||||
return this.body
|
||||
}
|
||||
|
||||
var isArray = Array.isArray || function (arr) {
|
||||
return Object.prototype.toString.call(arr) == '[object Array]'
|
||||
}
|
||||
|
||||
function isArrayish (arr) {
|
||||
return /Array\]$/.test(Object.prototype.toString.call(arr))
|
||||
}
|
||||
|
||||
function isBufferish (p) {
|
||||
return typeof p === 'string' || isArrayish(p) || (p && typeof p.subarray === 'function')
|
||||
}
|
||||
|
||||
function stringConcat (parts) {
|
||||
var strings = []
|
||||
var needsToString = false
|
||||
for (var i = 0; i < parts.length; i++) {
|
||||
var p = parts[i]
|
||||
if (typeof p === 'string') {
|
||||
strings.push(p)
|
||||
} else if (Buffer.isBuffer(p)) {
|
||||
strings.push(p)
|
||||
} else if (isBufferish(p)) {
|
||||
strings.push(bufferFrom(p))
|
||||
} else {
|
||||
strings.push(bufferFrom(String(p)))
|
||||
}
|
||||
}
|
||||
if (Buffer.isBuffer(parts[0])) {
|
||||
strings = Buffer.concat(strings)
|
||||
strings = strings.toString('utf8')
|
||||
} else {
|
||||
strings = strings.join('')
|
||||
}
|
||||
return strings
|
||||
}
|
||||
|
||||
function bufferConcat (parts) {
|
||||
var bufs = []
|
||||
for (var i = 0; i < parts.length; i++) {
|
||||
var p = parts[i]
|
||||
if (Buffer.isBuffer(p)) {
|
||||
bufs.push(p)
|
||||
} else if (isBufferish(p)) {
|
||||
bufs.push(bufferFrom(p))
|
||||
} else {
|
||||
bufs.push(bufferFrom(String(p)))
|
||||
}
|
||||
}
|
||||
return Buffer.concat(bufs)
|
||||
}
|
||||
|
||||
function arrayConcat (parts) {
|
||||
var res = []
|
||||
for (var i = 0; i < parts.length; i++) {
|
||||
res.push.apply(res, parts[i])
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
function u8Concat (parts) {
|
||||
var len = 0
|
||||
for (var i = 0; i < parts.length; i++) {
|
||||
if (typeof parts[i] === 'string') {
|
||||
parts[i] = bufferFrom(parts[i])
|
||||
}
|
||||
len += parts[i].length
|
||||
}
|
||||
var u8 = new U8(len)
|
||||
for (var i = 0, offset = 0; i < parts.length; i++) {
|
||||
var part = parts[i]
|
||||
for (var j = 0; j < part.length; j++) {
|
||||
u8[offset++] = part[j]
|
||||
}
|
||||
}
|
||||
return u8
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
before_install:
|
||||
- (test $NPM_LEGACY && npm install -g npm@2 && npm install -g npm@3) || true
|
||||
notifications:
|
||||
email: false
|
||||
matrix:
|
||||
fast_finish: true
|
||||
include:
|
||||
- node_js: '0.8'
|
||||
env: NPM_LEGACY=true
|
||||
- node_js: '0.10'
|
||||
env: NPM_LEGACY=true
|
||||
- node_js: '0.11'
|
||||
env: NPM_LEGACY=true
|
||||
- node_js: '0.12'
|
||||
env: NPM_LEGACY=true
|
||||
- node_js: 1
|
||||
env: NPM_LEGACY=true
|
||||
- node_js: 2
|
||||
env: NPM_LEGACY=true
|
||||
- node_js: 3
|
||||
env: NPM_LEGACY=true
|
||||
- node_js: 4
|
||||
- node_js: 5
|
||||
- node_js: 6
|
||||
- node_js: 7
|
||||
- node_js: 8
|
||||
- node_js: 9
|
||||
script: "npm run test"
|
||||
env:
|
||||
global:
|
||||
- secure: rE2Vvo7vnjabYNULNyLFxOyt98BoJexDqsiOnfiD6kLYYsiQGfr/sbZkPMOFm9qfQG7pjqx+zZWZjGSswhTt+626C0t/njXqug7Yps4c3dFblzGfreQHp7wNX5TFsvrxd6dAowVasMp61sJcRnB2w8cUzoe3RAYUDHyiHktwqMc=
|
||||
- secure: g9YINaKAdMatsJ28G9jCGbSaguXCyxSTy+pBO6Ch0Cf57ZLOTka3HqDj8p3nV28LUIHZ3ut5WO43CeYKwt4AUtLpBS3a0dndHdY6D83uY6b2qh5hXlrcbeQTq2cvw2y95F7hm4D1kwrgZ7ViqaKggRcEupAL69YbJnxeUDKWEdI=
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
# Developer's Certificate of Origin 1.1
|
||||
|
||||
By making a contribution to this project, I certify that:
|
||||
|
||||
* (a) The contribution was created in whole or in part by me and I
|
||||
have the right to submit it under the open source license
|
||||
indicated in the file; or
|
||||
|
||||
* (b) The contribution is based upon previous work that, to the best
|
||||
of my knowledge, is covered under an appropriate open source
|
||||
license and I have the right under that license to submit that
|
||||
work with modifications, whether created in whole or in part
|
||||
by me, under the same open source license (unless I am
|
||||
permitted to submit under a different license), as indicated
|
||||
in the file; or
|
||||
|
||||
* (c) The contribution was provided directly to me by some other
|
||||
person who certified (a), (b) or (c) and I have not modified
|
||||
it.
|
||||
|
||||
* (d) I understand and agree that this project and the contribution
|
||||
are public and that a record of the contribution (including all
|
||||
personal information I submit with it, including my sign-off) is
|
||||
maintained indefinitely and may be redistributed consistent with
|
||||
this project or the open source license(s) involved.
|
||||
|
||||
## Moderation Policy
|
||||
|
||||
The [Node.js Moderation Policy] applies to this WG.
|
||||
|
||||
## Code of Conduct
|
||||
|
||||
The [Node.js Code of Conduct][] applies to this WG.
|
||||
|
||||
[Node.js Code of Conduct]:
|
||||
https://github.com/nodejs/node/blob/master/CODE_OF_CONDUCT.md
|
||||
[Node.js Moderation Policy]:
|
||||
https://github.com/nodejs/TSC/blob/master/Moderation-Policy.md
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
### Streams Working Group
|
||||
|
||||
The Node.js Streams is jointly governed by a Working Group
|
||||
(WG)
|
||||
that is responsible for high-level guidance of the project.
|
||||
|
||||
The WG has final authority over this project including:
|
||||
|
||||
* Technical direction
|
||||
* Project governance and process (including this policy)
|
||||
* Contribution policy
|
||||
* GitHub repository hosting
|
||||
* Conduct guidelines
|
||||
* Maintaining the list of additional Collaborators
|
||||
|
||||
For the current list of WG members, see the project
|
||||
[README.md](./README.md#current-project-team-members).
|
||||
|
||||
### Collaborators
|
||||
|
||||
The readable-stream GitHub repository is
|
||||
maintained by the WG and additional Collaborators who are added by the
|
||||
WG on an ongoing basis.
|
||||
|
||||
Individuals making significant and valuable contributions are made
|
||||
Collaborators and given commit-access to the project. These
|
||||
individuals are identified by the WG and their addition as
|
||||
Collaborators is discussed during the WG meeting.
|
||||
|
||||
_Note:_ If you make a significant contribution and are not considered
|
||||
for commit-access log an issue or contact a WG member directly and it
|
||||
will be brought up in the next WG meeting.
|
||||
|
||||
Modifications of the contents of the readable-stream repository are
|
||||
made on
|
||||
a collaborative basis. Anybody with a GitHub account may propose a
|
||||
modification via pull request and it will be considered by the project
|
||||
Collaborators. All pull requests must be reviewed and accepted by a
|
||||
Collaborator with sufficient expertise who is able to take full
|
||||
responsibility for the change. In the case of pull requests proposed
|
||||
by an existing Collaborator, an additional Collaborator is required
|
||||
for sign-off. Consensus should be sought if additional Collaborators
|
||||
participate and there is disagreement around a particular
|
||||
modification. See _Consensus Seeking Process_ below for further detail
|
||||
on the consensus model used for governance.
|
||||
|
||||
Collaborators may opt to elevate significant or controversial
|
||||
modifications, or modifications that have not found consensus to the
|
||||
WG for discussion by assigning the ***WG-agenda*** tag to a pull
|
||||
request or issue. The WG should serve as the final arbiter where
|
||||
required.
|
||||
|
||||
For the current list of Collaborators, see the project
|
||||
[README.md](./README.md#members).
|
||||
|
||||
### WG Membership
|
||||
|
||||
WG seats are not time-limited. There is no fixed size of the WG.
|
||||
However, the expected target is between 6 and 12, to ensure adequate
|
||||
coverage of important areas of expertise, balanced with the ability to
|
||||
make decisions efficiently.
|
||||
|
||||
There is no specific set of requirements or qualifications for WG
|
||||
membership beyond these rules.
|
||||
|
||||
The WG may add additional members to the WG by unanimous consensus.
|
||||
|
||||
A WG member may be removed from the WG by voluntary resignation, or by
|
||||
unanimous consensus of all other WG members.
|
||||
|
||||
Changes to WG membership should be posted in the agenda, and may be
|
||||
suggested as any other agenda item (see "WG Meetings" below).
|
||||
|
||||
If an addition or removal is proposed during a meeting, and the full
|
||||
WG is not in attendance to participate, then the addition or removal
|
||||
is added to the agenda for the subsequent meeting. This is to ensure
|
||||
that all members are given the opportunity to participate in all
|
||||
membership decisions. If a WG member is unable to attend a meeting
|
||||
where a planned membership decision is being made, then their consent
|
||||
is assumed.
|
||||
|
||||
No more than 1/3 of the WG members may be affiliated with the same
|
||||
employer. If removal or resignation of a WG member, or a change of
|
||||
employment by a WG member, creates a situation where more than 1/3 of
|
||||
the WG membership shares an employer, then the situation must be
|
||||
immediately remedied by the resignation or removal of one or more WG
|
||||
members affiliated with the over-represented employer(s).
|
||||
|
||||
### WG Meetings
|
||||
|
||||
The WG meets occasionally on a Google Hangout On Air. A designated moderator
|
||||
approved by the WG runs the meeting. Each meeting should be
|
||||
published to YouTube.
|
||||
|
||||
Items are added to the WG agenda that are considered contentious or
|
||||
are modifications of governance, contribution policy, WG membership,
|
||||
or release process.
|
||||
|
||||
The intention of the agenda is not to approve or review all patches;
|
||||
that should happen continuously on GitHub and be handled by the larger
|
||||
group of Collaborators.
|
||||
|
||||
Any community member or contributor can ask that something be added to
|
||||
the next meeting's agenda by logging a GitHub Issue. Any Collaborator,
|
||||
WG member or the moderator can add the item to the agenda by adding
|
||||
the ***WG-agenda*** tag to the issue.
|
||||
|
||||
Prior to each WG meeting the moderator will share the Agenda with
|
||||
members of the WG. WG members can add any items they like to the
|
||||
agenda at the beginning of each meeting. The moderator and the WG
|
||||
cannot veto or remove items.
|
||||
|
||||
The WG may invite persons or representatives from certain projects to
|
||||
participate in a non-voting capacity.
|
||||
|
||||
The moderator is responsible for summarizing the discussion of each
|
||||
agenda item and sends it as a pull request after the meeting.
|
||||
|
||||
### Consensus Seeking Process
|
||||
|
||||
The WG follows a
|
||||
[Consensus
|
||||
Seeking](http://en.wikipedia.org/wiki/Consensus-seeking_decision-making)
|
||||
decision-making model.
|
||||
|
||||
When an agenda item has appeared to reach a consensus the moderator
|
||||
will ask "Does anyone object?" as a final call for dissent from the
|
||||
consensus.
|
||||
|
||||
If an agenda item cannot reach a consensus a WG member can call for
|
||||
either a closing vote or a vote to table the issue to the next
|
||||
meeting. The call for a vote must be seconded by a majority of the WG
|
||||
or else the discussion will continue. Simple majority wins.
|
||||
|
||||
Note that changes to WG membership require a majority consensus. See
|
||||
"WG Membership" above.
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
Node.js is licensed for use as follows:
|
||||
|
||||
"""
|
||||
Copyright Node.js contributors. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to
|
||||
deal in the Software without restriction, including without limitation the
|
||||
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
IN THE SOFTWARE.
|
||||
"""
|
||||
|
||||
This license applies to parts of Node.js originating from the
|
||||
https://github.com/joyent/node repository:
|
||||
|
||||
"""
|
||||
Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to
|
||||
deal in the Software without restriction, including without limitation the
|
||||
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
IN THE SOFTWARE.
|
||||
"""
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
# readable-stream
|
||||
|
||||
***Node-core v8.17.0 streams for userland*** [](https://travis-ci.org/nodejs/readable-stream)
|
||||
|
||||
|
||||
[](https://nodei.co/npm/readable-stream/)
|
||||
[](https://nodei.co/npm/readable-stream/)
|
||||
|
||||
|
||||
[](https://saucelabs.com/u/readable-stream)
|
||||
|
||||
```bash
|
||||
npm install --save readable-stream
|
||||
```
|
||||
|
||||
***Node-core streams for userland***
|
||||
|
||||
This package is a mirror of the Streams2 and Streams3 implementations in
|
||||
Node-core.
|
||||
|
||||
Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v8.17.0/docs/api/stream.html).
|
||||
|
||||
If you want to guarantee a stable streams base, regardless of what version of
|
||||
Node you, or the users of your libraries are using, use **readable-stream** *only* and avoid the *"stream"* module in Node-core, for background see [this blogpost](http://r.va.gg/2014/06/why-i-dont-use-nodes-core-stream-module.html).
|
||||
|
||||
As of version 2.0.0 **readable-stream** uses semantic versioning.
|
||||
|
||||
# Streams Working Group
|
||||
|
||||
`readable-stream` is maintained by the Streams Working Group, which
|
||||
oversees the development and maintenance of the Streams API within
|
||||
Node.js. The responsibilities of the Streams Working Group include:
|
||||
|
||||
* Addressing stream issues on the Node.js issue tracker.
|
||||
* Authoring and editing stream documentation within the Node.js project.
|
||||
* Reviewing changes to stream subclasses within the Node.js project.
|
||||
* Redirecting changes to streams from the Node.js project to this
|
||||
project.
|
||||
* Assisting in the implementation of stream providers within Node.js.
|
||||
* Recommending versions of `readable-stream` to be included in Node.js.
|
||||
* Messaging about the future of streams to give the community advance
|
||||
notice of changes.
|
||||
|
||||
<a name="members"></a>
|
||||
## Team Members
|
||||
|
||||
* **Chris Dickinson** ([@chrisdickinson](https://github.com/chrisdickinson)) <christopher.s.dickinson@gmail.com>
|
||||
- Release GPG key: 9554F04D7259F04124DE6B476D5A82AC7E37093B
|
||||
* **Calvin Metcalf** ([@calvinmetcalf](https://github.com/calvinmetcalf)) <calvin.metcalf@gmail.com>
|
||||
- Release GPG key: F3EF5F62A87FC27A22E643F714CE4FF5015AA242
|
||||
* **Rod Vagg** ([@rvagg](https://github.com/rvagg)) <rod@vagg.org>
|
||||
- Release GPG key: DD8F2338BAE7501E3DD5AC78C273792F7D83545D
|
||||
* **Sam Newman** ([@sonewman](https://github.com/sonewman)) <newmansam@outlook.com>
|
||||
* **Mathias Buus** ([@mafintosh](https://github.com/mafintosh)) <mathiasbuus@gmail.com>
|
||||
* **Domenic Denicola** ([@domenic](https://github.com/domenic)) <d@domenic.me>
|
||||
* **Matteo Collina** ([@mcollina](https://github.com/mcollina)) <matteo.collina@gmail.com>
|
||||
- Release GPG key: 3ABC01543F22DD2239285CDD818674489FBC127E
|
||||
* **Irina Shestak** ([@lrlna](https://github.com/lrlna)) <shestak.irina@gmail.com>
|
||||
Generated
Vendored
+60
@@ -0,0 +1,60 @@
|
||||
# streams WG Meeting 2015-01-30
|
||||
|
||||
## Links
|
||||
|
||||
* **Google Hangouts Video**: http://www.youtube.com/watch?v=I9nDOSGfwZg
|
||||
* **GitHub Issue**: https://github.com/iojs/readable-stream/issues/106
|
||||
* **Original Minutes Google Doc**: https://docs.google.com/document/d/17aTgLnjMXIrfjgNaTUnHQO7m3xgzHR2VXBTmi03Qii4/
|
||||
|
||||
## Agenda
|
||||
|
||||
Extracted from https://github.com/iojs/readable-stream/labels/wg-agenda prior to meeting.
|
||||
|
||||
* adopt a charter [#105](https://github.com/iojs/readable-stream/issues/105)
|
||||
* release and versioning strategy [#101](https://github.com/iojs/readable-stream/issues/101)
|
||||
* simpler stream creation [#102](https://github.com/iojs/readable-stream/issues/102)
|
||||
* proposal: deprecate implicit flowing of streams [#99](https://github.com/iojs/readable-stream/issues/99)
|
||||
|
||||
## Minutes
|
||||
|
||||
### adopt a charter
|
||||
|
||||
* group: +1's all around
|
||||
|
||||
### What versioning scheme should be adopted?
|
||||
* group: +1’s 3.0.0
|
||||
* domenic+group: pulling in patches from other sources where appropriate
|
||||
* mikeal: version independently, suggesting versions for io.js
|
||||
* mikeal+domenic: work with TC to notify in advance of changes
|
||||
simpler stream creation
|
||||
|
||||
### streamline creation of streams
|
||||
* sam: streamline creation of streams
|
||||
* domenic: nice simple solution posted
|
||||
but, we lose the opportunity to change the model
|
||||
may not be backwards incompatible (double check keys)
|
||||
|
||||
**action item:** domenic will check
|
||||
|
||||
### remove implicit flowing of streams on(‘data’)
|
||||
* add isFlowing / isPaused
|
||||
* mikeal: worrying that we’re documenting polyfill methods – confuses users
|
||||
* domenic: more reflective API is probably good, with warning labels for users
|
||||
* new section for mad scientists (reflective stream access)
|
||||
* calvin: name the “third state”
|
||||
* mikeal: maybe borrow the name from whatwg?
|
||||
* domenic: we’re missing the “third state”
|
||||
* consensus: kind of difficult to name the third state
|
||||
* mikeal: figure out differences in states / compat
|
||||
* mathias: always flow on data – eliminates third state
|
||||
* explore what it breaks
|
||||
|
||||
**action items:**
|
||||
* ask isaac for ability to list packages by what public io.js APIs they use (esp. Stream)
|
||||
* ask rod/build for infrastructure
|
||||
* **chris**: explore the “flow on data” approach
|
||||
* add isPaused/isFlowing
|
||||
* add new docs section
|
||||
* move isPaused to that section
|
||||
|
||||
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
module.exports = require('./lib/_stream_duplex.js');
|
||||
+1
@@ -0,0 +1 @@
|
||||
module.exports = require('./readable').Duplex
|
||||
Generated
Vendored
+131
@@ -0,0 +1,131 @@
|
||||
// Copyright Joyent, Inc. and other Node contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||
// persons to whom the Software is furnished to do so, subject to the
|
||||
// following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// a duplex stream is just a stream that is both readable and writable.
|
||||
// Since JS doesn't have multiple prototypal inheritance, this class
|
||||
// prototypally inherits from Readable, and then parasitically from
|
||||
// Writable.
|
||||
|
||||
'use strict';
|
||||
|
||||
/*<replacement>*/
|
||||
|
||||
var pna = require('process-nextick-args');
|
||||
/*</replacement>*/
|
||||
|
||||
/*<replacement>*/
|
||||
var objectKeys = Object.keys || function (obj) {
|
||||
var keys = [];
|
||||
for (var key in obj) {
|
||||
keys.push(key);
|
||||
}return keys;
|
||||
};
|
||||
/*</replacement>*/
|
||||
|
||||
module.exports = Duplex;
|
||||
|
||||
/*<replacement>*/
|
||||
var util = Object.create(require('core-util-is'));
|
||||
util.inherits = require('inherits');
|
||||
/*</replacement>*/
|
||||
|
||||
var Readable = require('./_stream_readable');
|
||||
var Writable = require('./_stream_writable');
|
||||
|
||||
util.inherits(Duplex, Readable);
|
||||
|
||||
{
|
||||
// avoid scope creep, the keys array can then be collected
|
||||
var keys = objectKeys(Writable.prototype);
|
||||
for (var v = 0; v < keys.length; v++) {
|
||||
var method = keys[v];
|
||||
if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
|
||||
}
|
||||
}
|
||||
|
||||
function Duplex(options) {
|
||||
if (!(this instanceof Duplex)) return new Duplex(options);
|
||||
|
||||
Readable.call(this, options);
|
||||
Writable.call(this, options);
|
||||
|
||||
if (options && options.readable === false) this.readable = false;
|
||||
|
||||
if (options && options.writable === false) this.writable = false;
|
||||
|
||||
this.allowHalfOpen = true;
|
||||
if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
|
||||
|
||||
this.once('end', onend);
|
||||
}
|
||||
|
||||
Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
|
||||
// making it explicit this property is not enumerable
|
||||
// because otherwise some prototype manipulation in
|
||||
// userland will fail
|
||||
enumerable: false,
|
||||
get: function () {
|
||||
return this._writableState.highWaterMark;
|
||||
}
|
||||
});
|
||||
|
||||
// the no-half-open enforcer
|
||||
function onend() {
|
||||
// if we allow half-open state, or if the writable side ended,
|
||||
// then we're ok.
|
||||
if (this.allowHalfOpen || this._writableState.ended) return;
|
||||
|
||||
// no more data can be written.
|
||||
// But allow more writes to happen in this tick.
|
||||
pna.nextTick(onEndNT, this);
|
||||
}
|
||||
|
||||
function onEndNT(self) {
|
||||
self.end();
|
||||
}
|
||||
|
||||
Object.defineProperty(Duplex.prototype, 'destroyed', {
|
||||
get: function () {
|
||||
if (this._readableState === undefined || this._writableState === undefined) {
|
||||
return false;
|
||||
}
|
||||
return this._readableState.destroyed && this._writableState.destroyed;
|
||||
},
|
||||
set: function (value) {
|
||||
// we ignore the value if the stream
|
||||
// has not been initialized yet
|
||||
if (this._readableState === undefined || this._writableState === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
// backward compatibility, the user is explicitly
|
||||
// managing destroyed
|
||||
this._readableState.destroyed = value;
|
||||
this._writableState.destroyed = value;
|
||||
}
|
||||
});
|
||||
|
||||
Duplex.prototype._destroy = function (err, cb) {
|
||||
this.push(null);
|
||||
this.end();
|
||||
|
||||
pna.nextTick(cb, err);
|
||||
};
|
||||
Generated
Vendored
+47
@@ -0,0 +1,47 @@
|
||||
// Copyright Joyent, Inc. and other Node contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||
// persons to whom the Software is furnished to do so, subject to the
|
||||
// following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// a passthrough stream.
|
||||
// basically just the most minimal sort of Transform stream.
|
||||
// Every written chunk gets output as-is.
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = PassThrough;
|
||||
|
||||
var Transform = require('./_stream_transform');
|
||||
|
||||
/*<replacement>*/
|
||||
var util = Object.create(require('core-util-is'));
|
||||
util.inherits = require('inherits');
|
||||
/*</replacement>*/
|
||||
|
||||
util.inherits(PassThrough, Transform);
|
||||
|
||||
function PassThrough(options) {
|
||||
if (!(this instanceof PassThrough)) return new PassThrough(options);
|
||||
|
||||
Transform.call(this, options);
|
||||
}
|
||||
|
||||
PassThrough.prototype._transform = function (chunk, encoding, cb) {
|
||||
cb(null, chunk);
|
||||
};
|
||||
Generated
Vendored
+1019
File diff suppressed because it is too large
Load Diff
Generated
Vendored
+214
@@ -0,0 +1,214 @@
|
||||
// Copyright Joyent, Inc. and other Node contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||
// persons to whom the Software is furnished to do so, subject to the
|
||||
// following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// a transform stream is a readable/writable stream where you do
|
||||
// something with the data. Sometimes it's called a "filter",
|
||||
// but that's not a great name for it, since that implies a thing where
|
||||
// some bits pass through, and others are simply ignored. (That would
|
||||
// be a valid example of a transform, of course.)
|
||||
//
|
||||
// While the output is causally related to the input, it's not a
|
||||
// necessarily symmetric or synchronous transformation. For example,
|
||||
// a zlib stream might take multiple plain-text writes(), and then
|
||||
// emit a single compressed chunk some time in the future.
|
||||
//
|
||||
// Here's how this works:
|
||||
//
|
||||
// The Transform stream has all the aspects of the readable and writable
|
||||
// stream classes. When you write(chunk), that calls _write(chunk,cb)
|
||||
// internally, and returns false if there's a lot of pending writes
|
||||
// buffered up. When you call read(), that calls _read(n) until
|
||||
// there's enough pending readable data buffered up.
|
||||
//
|
||||
// In a transform stream, the written data is placed in a buffer. When
|
||||
// _read(n) is called, it transforms the queued up data, calling the
|
||||
// buffered _write cb's as it consumes chunks. If consuming a single
|
||||
// written chunk would result in multiple output chunks, then the first
|
||||
// outputted bit calls the readcb, and subsequent chunks just go into
|
||||
// the read buffer, and will cause it to emit 'readable' if necessary.
|
||||
//
|
||||
// This way, back-pressure is actually determined by the reading side,
|
||||
// since _read has to be called to start processing a new chunk. However,
|
||||
// a pathological inflate type of transform can cause excessive buffering
|
||||
// here. For example, imagine a stream where every byte of input is
|
||||
// interpreted as an integer from 0-255, and then results in that many
|
||||
// bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
|
||||
// 1kb of data being output. In this case, you could write a very small
|
||||
// amount of input, and end up with a very large amount of output. In
|
||||
// such a pathological inflating mechanism, there'd be no way to tell
|
||||
// the system to stop doing the transform. A single 4MB write could
|
||||
// cause the system to run out of memory.
|
||||
//
|
||||
// However, even in such a pathological case, only a single written chunk
|
||||
// would be consumed, and then the rest would wait (un-transformed) until
|
||||
// the results of the previous transformed chunk were consumed.
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = Transform;
|
||||
|
||||
var Duplex = require('./_stream_duplex');
|
||||
|
||||
/*<replacement>*/
|
||||
var util = Object.create(require('core-util-is'));
|
||||
util.inherits = require('inherits');
|
||||
/*</replacement>*/
|
||||
|
||||
util.inherits(Transform, Duplex);
|
||||
|
||||
function afterTransform(er, data) {
|
||||
var ts = this._transformState;
|
||||
ts.transforming = false;
|
||||
|
||||
var cb = ts.writecb;
|
||||
|
||||
if (!cb) {
|
||||
return this.emit('error', new Error('write callback called multiple times'));
|
||||
}
|
||||
|
||||
ts.writechunk = null;
|
||||
ts.writecb = null;
|
||||
|
||||
if (data != null) // single equals check for both `null` and `undefined`
|
||||
this.push(data);
|
||||
|
||||
cb(er);
|
||||
|
||||
var rs = this._readableState;
|
||||
rs.reading = false;
|
||||
if (rs.needReadable || rs.length < rs.highWaterMark) {
|
||||
this._read(rs.highWaterMark);
|
||||
}
|
||||
}
|
||||
|
||||
function Transform(options) {
|
||||
if (!(this instanceof Transform)) return new Transform(options);
|
||||
|
||||
Duplex.call(this, options);
|
||||
|
||||
this._transformState = {
|
||||
afterTransform: afterTransform.bind(this),
|
||||
needTransform: false,
|
||||
transforming: false,
|
||||
writecb: null,
|
||||
writechunk: null,
|
||||
writeencoding: null
|
||||
};
|
||||
|
||||
// start out asking for a readable event once data is transformed.
|
||||
this._readableState.needReadable = true;
|
||||
|
||||
// we have implemented the _read method, and done the other things
|
||||
// that Readable wants before the first _read call, so unset the
|
||||
// sync guard flag.
|
||||
this._readableState.sync = false;
|
||||
|
||||
if (options) {
|
||||
if (typeof options.transform === 'function') this._transform = options.transform;
|
||||
|
||||
if (typeof options.flush === 'function') this._flush = options.flush;
|
||||
}
|
||||
|
||||
// When the writable side finishes, then flush out anything remaining.
|
||||
this.on('prefinish', prefinish);
|
||||
}
|
||||
|
||||
function prefinish() {
|
||||
var _this = this;
|
||||
|
||||
if (typeof this._flush === 'function') {
|
||||
this._flush(function (er, data) {
|
||||
done(_this, er, data);
|
||||
});
|
||||
} else {
|
||||
done(this, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
Transform.prototype.push = function (chunk, encoding) {
|
||||
this._transformState.needTransform = false;
|
||||
return Duplex.prototype.push.call(this, chunk, encoding);
|
||||
};
|
||||
|
||||
// This is the part where you do stuff!
|
||||
// override this function in implementation classes.
|
||||
// 'chunk' is an input chunk.
|
||||
//
|
||||
// Call `push(newChunk)` to pass along transformed output
|
||||
// to the readable side. You may call 'push' zero or more times.
|
||||
//
|
||||
// Call `cb(err)` when you are done with this chunk. If you pass
|
||||
// an error, then that'll put the hurt on the whole operation. If you
|
||||
// never call cb(), then you'll never get another chunk.
|
||||
Transform.prototype._transform = function (chunk, encoding, cb) {
|
||||
throw new Error('_transform() is not implemented');
|
||||
};
|
||||
|
||||
Transform.prototype._write = function (chunk, encoding, cb) {
|
||||
var ts = this._transformState;
|
||||
ts.writecb = cb;
|
||||
ts.writechunk = chunk;
|
||||
ts.writeencoding = encoding;
|
||||
if (!ts.transforming) {
|
||||
var rs = this._readableState;
|
||||
if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
|
||||
}
|
||||
};
|
||||
|
||||
// Doesn't matter what the args are here.
|
||||
// _transform does all the work.
|
||||
// That we got here means that the readable side wants more data.
|
||||
Transform.prototype._read = function (n) {
|
||||
var ts = this._transformState;
|
||||
|
||||
if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
|
||||
ts.transforming = true;
|
||||
this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
|
||||
} else {
|
||||
// mark that we need a transform, so that any data that comes in
|
||||
// will get processed, now that we've asked for it.
|
||||
ts.needTransform = true;
|
||||
}
|
||||
};
|
||||
|
||||
Transform.prototype._destroy = function (err, cb) {
|
||||
var _this2 = this;
|
||||
|
||||
Duplex.prototype._destroy.call(this, err, function (err2) {
|
||||
cb(err2);
|
||||
_this2.emit('close');
|
||||
});
|
||||
};
|
||||
|
||||
function done(stream, er, data) {
|
||||
if (er) return stream.emit('error', er);
|
||||
|
||||
if (data != null) // single equals check for both `null` and `undefined`
|
||||
stream.push(data);
|
||||
|
||||
// if there's nothing in the write buffer, then that means
|
||||
// that nothing more will ever be provided
|
||||
if (stream._writableState.length) throw new Error('Calling transform done when ws.length != 0');
|
||||
|
||||
if (stream._transformState.transforming) throw new Error('Calling transform done when still transforming');
|
||||
|
||||
return stream.push(null);
|
||||
}
|
||||
Generated
Vendored
+685
@@ -0,0 +1,685 @@
|
||||
// Copyright Joyent, Inc. and other Node contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||
// persons to whom the Software is furnished to do so, subject to the
|
||||
// following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// A bit simpler than readable streams.
|
||||
// Implement an async ._write(chunk, encoding, cb), and it'll handle all
|
||||
// the drain event emission and buffering.
|
||||
|
||||
'use strict';
|
||||
|
||||
/*<replacement>*/
|
||||
|
||||
var pna = require('process-nextick-args');
|
||||
/*</replacement>*/
|
||||
|
||||
module.exports = Writable;
|
||||
|
||||
/* <replacement> */
|
||||
function WriteReq(chunk, encoding, cb) {
|
||||
this.chunk = chunk;
|
||||
this.encoding = encoding;
|
||||
this.callback = cb;
|
||||
this.next = null;
|
||||
}
|
||||
|
||||
// It seems a linked list but it is not
|
||||
// there will be only 2 of these for each stream
|
||||
function CorkedRequest(state) {
|
||||
var _this = this;
|
||||
|
||||
this.next = null;
|
||||
this.entry = null;
|
||||
this.finish = function () {
|
||||
onCorkedFinish(_this, state);
|
||||
};
|
||||
}
|
||||
/* </replacement> */
|
||||
|
||||
/*<replacement>*/
|
||||
var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : pna.nextTick;
|
||||
/*</replacement>*/
|
||||
|
||||
/*<replacement>*/
|
||||
var Duplex;
|
||||
/*</replacement>*/
|
||||
|
||||
Writable.WritableState = WritableState;
|
||||
|
||||
/*<replacement>*/
|
||||
var util = Object.create(require('core-util-is'));
|
||||
util.inherits = require('inherits');
|
||||
/*</replacement>*/
|
||||
|
||||
/*<replacement>*/
|
||||
var internalUtil = {
|
||||
deprecate: require('util-deprecate')
|
||||
};
|
||||
/*</replacement>*/
|
||||
|
||||
/*<replacement>*/
|
||||
var Stream = require('./internal/streams/stream');
|
||||
/*</replacement>*/
|
||||
|
||||
/*<replacement>*/
|
||||
|
||||
var Buffer = require('safe-buffer').Buffer;
|
||||
var OurUint8Array = (typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {};
|
||||
function _uint8ArrayToBuffer(chunk) {
|
||||
return Buffer.from(chunk);
|
||||
}
|
||||
function _isUint8Array(obj) {
|
||||
return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
|
||||
}
|
||||
|
||||
/*</replacement>*/
|
||||
|
||||
var destroyImpl = require('./internal/streams/destroy');
|
||||
|
||||
util.inherits(Writable, Stream);
|
||||
|
||||
function nop() {}
|
||||
|
||||
function WritableState(options, stream) {
|
||||
Duplex = Duplex || require('./_stream_duplex');
|
||||
|
||||
options = options || {};
|
||||
|
||||
// Duplex streams are both readable and writable, but share
|
||||
// the same options object.
|
||||
// However, some cases require setting options to different
|
||||
// values for the readable and the writable sides of the duplex stream.
|
||||
// These options can be provided separately as readableXXX and writableXXX.
|
||||
var isDuplex = stream instanceof Duplex;
|
||||
|
||||
// object stream flag to indicate whether or not this stream
|
||||
// contains buffers or objects.
|
||||
this.objectMode = !!options.objectMode;
|
||||
|
||||
if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
|
||||
|
||||
// the point at which write() starts returning false
|
||||
// Note: 0 is a valid value, means that we always return false if
|
||||
// the entire buffer is not flushed immediately on write()
|
||||
var hwm = options.highWaterMark;
|
||||
var writableHwm = options.writableHighWaterMark;
|
||||
var defaultHwm = this.objectMode ? 16 : 16 * 1024;
|
||||
|
||||
if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (writableHwm || writableHwm === 0)) this.highWaterMark = writableHwm;else this.highWaterMark = defaultHwm;
|
||||
|
||||
// cast to ints.
|
||||
this.highWaterMark = Math.floor(this.highWaterMark);
|
||||
|
||||
// if _final has been called
|
||||
this.finalCalled = false;
|
||||
|
||||
// drain event flag.
|
||||
this.needDrain = false;
|
||||
// at the start of calling end()
|
||||
this.ending = false;
|
||||
// when end() has been called, and returned
|
||||
this.ended = false;
|
||||
// when 'finish' is emitted
|
||||
this.finished = false;
|
||||
|
||||
// has it been destroyed
|
||||
this.destroyed = false;
|
||||
|
||||
// should we decode strings into buffers before passing to _write?
|
||||
// this is here so that some node-core streams can optimize string
|
||||
// handling at a lower level.
|
||||
var noDecode = options.decodeStrings === false;
|
||||
this.decodeStrings = !noDecode;
|
||||
|
||||
// Crypto is kind of old and crusty. Historically, its default string
|
||||
// encoding is 'binary' so we have to make this configurable.
|
||||
// Everything else in the universe uses 'utf8', though.
|
||||
this.defaultEncoding = options.defaultEncoding || 'utf8';
|
||||
|
||||
// not an actual buffer we keep track of, but a measurement
|
||||
// of how much we're waiting to get pushed to some underlying
|
||||
// socket or file.
|
||||
this.length = 0;
|
||||
|
||||
// a flag to see when we're in the middle of a write.
|
||||
this.writing = false;
|
||||
|
||||
// when true all writes will be buffered until .uncork() call
|
||||
this.corked = 0;
|
||||
|
||||
// a flag to be able to tell if the onwrite cb is called immediately,
|
||||
// or on a later tick. We set this to true at first, because any
|
||||
// actions that shouldn't happen until "later" should generally also
|
||||
// not happen before the first write call.
|
||||
this.sync = true;
|
||||
|
||||
// a flag to know if we're processing previously buffered items, which
|
||||
// may call the _write() callback in the same tick, so that we don't
|
||||
// end up in an overlapped onwrite situation.
|
||||
this.bufferProcessing = false;
|
||||
|
||||
// the callback that's passed to _write(chunk,cb)
|
||||
this.onwrite = function (er) {
|
||||
onwrite(stream, er);
|
||||
};
|
||||
|
||||
// the callback that the user supplies to write(chunk,encoding,cb)
|
||||
this.writecb = null;
|
||||
|
||||
// the amount that is being written when _write is called.
|
||||
this.writelen = 0;
|
||||
|
||||
this.bufferedRequest = null;
|
||||
this.lastBufferedRequest = null;
|
||||
|
||||
// number of pending user-supplied write callbacks
|
||||
// this must be 0 before 'finish' can be emitted
|
||||
this.pendingcb = 0;
|
||||
|
||||
// emit prefinish if the only thing we're waiting for is _write cbs
|
||||
// This is relevant for synchronous Transform streams
|
||||
this.prefinished = false;
|
||||
|
||||
// True if the error was already emitted and should not be thrown again
|
||||
this.errorEmitted = false;
|
||||
|
||||
// count buffered requests
|
||||
this.bufferedRequestCount = 0;
|
||||
|
||||
// allocate the first CorkedRequest, there is always
|
||||
// one allocated and free to use, and we maintain at most two
|
||||
this.corkedRequestsFree = new CorkedRequest(this);
|
||||
}
|
||||
|
||||
WritableState.prototype.getBuffer = function getBuffer() {
|
||||
var current = this.bufferedRequest;
|
||||
var out = [];
|
||||
while (current) {
|
||||
out.push(current);
|
||||
current = current.next;
|
||||
}
|
||||
return out;
|
||||
};
|
||||
|
||||
(function () {
|
||||
try {
|
||||
Object.defineProperty(WritableState.prototype, 'buffer', {
|
||||
get: internalUtil.deprecate(function () {
|
||||
return this.getBuffer();
|
||||
}, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
|
||||
});
|
||||
} catch (_) {}
|
||||
})();
|
||||
|
||||
// Test _writableState for inheritance to account for Duplex streams,
|
||||
// whose prototype chain only points to Readable.
|
||||
var realHasInstance;
|
||||
if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
|
||||
realHasInstance = Function.prototype[Symbol.hasInstance];
|
||||
Object.defineProperty(Writable, Symbol.hasInstance, {
|
||||
value: function (object) {
|
||||
if (realHasInstance.call(this, object)) return true;
|
||||
if (this !== Writable) return false;
|
||||
|
||||
return object && object._writableState instanceof WritableState;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
realHasInstance = function (object) {
|
||||
return object instanceof this;
|
||||
};
|
||||
}
|
||||
|
||||
function Writable(options) {
|
||||
Duplex = Duplex || require('./_stream_duplex');
|
||||
|
||||
// Writable ctor is applied to Duplexes, too.
|
||||
// `realHasInstance` is necessary because using plain `instanceof`
|
||||
// would return false, as no `_writableState` property is attached.
|
||||
|
||||
// Trying to use the custom `instanceof` for Writable here will also break the
|
||||
// Node.js LazyTransform implementation, which has a non-trivial getter for
|
||||
// `_writableState` that would lead to infinite recursion.
|
||||
if (!realHasInstance.call(Writable, this) && !(this instanceof Duplex)) {
|
||||
return new Writable(options);
|
||||
}
|
||||
|
||||
this._writableState = new WritableState(options, this);
|
||||
|
||||
// legacy.
|
||||
this.writable = true;
|
||||
|
||||
if (options) {
|
||||
if (typeof options.write === 'function') this._write = options.write;
|
||||
|
||||
if (typeof options.writev === 'function') this._writev = options.writev;
|
||||
|
||||
if (typeof options.destroy === 'function') this._destroy = options.destroy;
|
||||
|
||||
if (typeof options.final === 'function') this._final = options.final;
|
||||
}
|
||||
|
||||
Stream.call(this);
|
||||
}
|
||||
|
||||
// Otherwise people can pipe Writable streams, which is just wrong.
|
||||
Writable.prototype.pipe = function () {
|
||||
this.emit('error', new Error('Cannot pipe, not readable'));
|
||||
};
|
||||
|
||||
function writeAfterEnd(stream, cb) {
|
||||
var er = new Error('write after end');
|
||||
// TODO: defer error events consistently everywhere, not just the cb
|
||||
stream.emit('error', er);
|
||||
pna.nextTick(cb, er);
|
||||
}
|
||||
|
||||
// Checks that a user-supplied chunk is valid, especially for the particular
|
||||
// mode the stream is in. Currently this means that `null` is never accepted
|
||||
// and undefined/non-string values are only allowed in object mode.
|
||||
function validChunk(stream, state, chunk, cb) {
|
||||
var valid = true;
|
||||
var er = false;
|
||||
|
||||
if (chunk === null) {
|
||||
er = new TypeError('May not write null values to stream');
|
||||
} else if (typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
|
||||
er = new TypeError('Invalid non-string/buffer chunk');
|
||||
}
|
||||
if (er) {
|
||||
stream.emit('error', er);
|
||||
pna.nextTick(cb, er);
|
||||
valid = false;
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
Writable.prototype.write = function (chunk, encoding, cb) {
|
||||
var state = this._writableState;
|
||||
var ret = false;
|
||||
var isBuf = !state.objectMode && _isUint8Array(chunk);
|
||||
|
||||
if (isBuf && !Buffer.isBuffer(chunk)) {
|
||||
chunk = _uint8ArrayToBuffer(chunk);
|
||||
}
|
||||
|
||||
if (typeof encoding === 'function') {
|
||||
cb = encoding;
|
||||
encoding = null;
|
||||
}
|
||||
|
||||
if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
|
||||
|
||||
if (typeof cb !== 'function') cb = nop;
|
||||
|
||||
if (state.ended) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
|
||||
state.pendingcb++;
|
||||
ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
Writable.prototype.cork = function () {
|
||||
var state = this._writableState;
|
||||
|
||||
state.corked++;
|
||||
};
|
||||
|
||||
Writable.prototype.uncork = function () {
|
||||
var state = this._writableState;
|
||||
|
||||
if (state.corked) {
|
||||
state.corked--;
|
||||
|
||||
if (!state.writing && !state.corked && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
|
||||
}
|
||||
};
|
||||
|
||||
Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
|
||||
// node::ParseEncoding() requires lower case.
|
||||
if (typeof encoding === 'string') encoding = encoding.toLowerCase();
|
||||
if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new TypeError('Unknown encoding: ' + encoding);
|
||||
this._writableState.defaultEncoding = encoding;
|
||||
return this;
|
||||
};
|
||||
|
||||
function decodeChunk(state, chunk, encoding) {
|
||||
if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
|
||||
chunk = Buffer.from(chunk, encoding);
|
||||
}
|
||||
return chunk;
|
||||
}
|
||||
|
||||
Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
|
||||
// making it explicit this property is not enumerable
|
||||
// because otherwise some prototype manipulation in
|
||||
// userland will fail
|
||||
enumerable: false,
|
||||
get: function () {
|
||||
return this._writableState.highWaterMark;
|
||||
}
|
||||
});
|
||||
|
||||
// if we're already writing something, then just put this
|
||||
// in the queue, and wait our turn. Otherwise, call _write
|
||||
// If we return false, then we need a drain event, so set that flag.
|
||||
function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
|
||||
if (!isBuf) {
|
||||
var newChunk = decodeChunk(state, chunk, encoding);
|
||||
if (chunk !== newChunk) {
|
||||
isBuf = true;
|
||||
encoding = 'buffer';
|
||||
chunk = newChunk;
|
||||
}
|
||||
}
|
||||
var len = state.objectMode ? 1 : chunk.length;
|
||||
|
||||
state.length += len;
|
||||
|
||||
var ret = state.length < state.highWaterMark;
|
||||
// we must ensure that previous needDrain will not be reset to false.
|
||||
if (!ret) state.needDrain = true;
|
||||
|
||||
if (state.writing || state.corked) {
|
||||
var last = state.lastBufferedRequest;
|
||||
state.lastBufferedRequest = {
|
||||
chunk: chunk,
|
||||
encoding: encoding,
|
||||
isBuf: isBuf,
|
||||
callback: cb,
|
||||
next: null
|
||||
};
|
||||
if (last) {
|
||||
last.next = state.lastBufferedRequest;
|
||||
} else {
|
||||
state.bufferedRequest = state.lastBufferedRequest;
|
||||
}
|
||||
state.bufferedRequestCount += 1;
|
||||
} else {
|
||||
doWrite(stream, state, false, len, chunk, encoding, cb);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
function doWrite(stream, state, writev, len, chunk, encoding, cb) {
|
||||
state.writelen = len;
|
||||
state.writecb = cb;
|
||||
state.writing = true;
|
||||
state.sync = true;
|
||||
if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
|
||||
state.sync = false;
|
||||
}
|
||||
|
||||
function onwriteError(stream, state, sync, er, cb) {
|
||||
--state.pendingcb;
|
||||
|
||||
if (sync) {
|
||||
// defer the callback if we are being called synchronously
|
||||
// to avoid piling up things on the stack
|
||||
pna.nextTick(cb, er);
|
||||
// this can emit finish, and it will always happen
|
||||
// after error
|
||||
pna.nextTick(finishMaybe, stream, state);
|
||||
stream._writableState.errorEmitted = true;
|
||||
stream.emit('error', er);
|
||||
} else {
|
||||
// the caller expect this to happen before if
|
||||
// it is async
|
||||
cb(er);
|
||||
stream._writableState.errorEmitted = true;
|
||||
stream.emit('error', er);
|
||||
// this can emit finish, but finish must
|
||||
// always follow error
|
||||
finishMaybe(stream, state);
|
||||
}
|
||||
}
|
||||
|
||||
function onwriteStateUpdate(state) {
|
||||
state.writing = false;
|
||||
state.writecb = null;
|
||||
state.length -= state.writelen;
|
||||
state.writelen = 0;
|
||||
}
|
||||
|
||||
function onwrite(stream, er) {
|
||||
var state = stream._writableState;
|
||||
var sync = state.sync;
|
||||
var cb = state.writecb;
|
||||
|
||||
onwriteStateUpdate(state);
|
||||
|
||||
if (er) onwriteError(stream, state, sync, er, cb);else {
|
||||
// Check if we're actually ready to finish, but don't emit yet
|
||||
var finished = needFinish(state);
|
||||
|
||||
if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
|
||||
clearBuffer(stream, state);
|
||||
}
|
||||
|
||||
if (sync) {
|
||||
/*<replacement>*/
|
||||
asyncWrite(afterWrite, stream, state, finished, cb);
|
||||
/*</replacement>*/
|
||||
} else {
|
||||
afterWrite(stream, state, finished, cb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function afterWrite(stream, state, finished, cb) {
|
||||
if (!finished) onwriteDrain(stream, state);
|
||||
state.pendingcb--;
|
||||
cb();
|
||||
finishMaybe(stream, state);
|
||||
}
|
||||
|
||||
// Must force callback to be called on nextTick, so that we don't
|
||||
// emit 'drain' before the write() consumer gets the 'false' return
|
||||
// value, and has a chance to attach a 'drain' listener.
|
||||
function onwriteDrain(stream, state) {
|
||||
if (state.length === 0 && state.needDrain) {
|
||||
state.needDrain = false;
|
||||
stream.emit('drain');
|
||||
}
|
||||
}
|
||||
|
||||
// if there's something in the buffer waiting, then process it
|
||||
function clearBuffer(stream, state) {
|
||||
state.bufferProcessing = true;
|
||||
var entry = state.bufferedRequest;
|
||||
|
||||
if (stream._writev && entry && entry.next) {
|
||||
// Fast case, write everything using _writev()
|
||||
var l = state.bufferedRequestCount;
|
||||
var buffer = new Array(l);
|
||||
var holder = state.corkedRequestsFree;
|
||||
holder.entry = entry;
|
||||
|
||||
var count = 0;
|
||||
var allBuffers = true;
|
||||
while (entry) {
|
||||
buffer[count] = entry;
|
||||
if (!entry.isBuf) allBuffers = false;
|
||||
entry = entry.next;
|
||||
count += 1;
|
||||
}
|
||||
buffer.allBuffers = allBuffers;
|
||||
|
||||
doWrite(stream, state, true, state.length, buffer, '', holder.finish);
|
||||
|
||||
// doWrite is almost always async, defer these to save a bit of time
|
||||
// as the hot path ends with doWrite
|
||||
state.pendingcb++;
|
||||
state.lastBufferedRequest = null;
|
||||
if (holder.next) {
|
||||
state.corkedRequestsFree = holder.next;
|
||||
holder.next = null;
|
||||
} else {
|
||||
state.corkedRequestsFree = new CorkedRequest(state);
|
||||
}
|
||||
state.bufferedRequestCount = 0;
|
||||
} else {
|
||||
// Slow case, write chunks one-by-one
|
||||
while (entry) {
|
||||
var chunk = entry.chunk;
|
||||
var encoding = entry.encoding;
|
||||
var cb = entry.callback;
|
||||
var len = state.objectMode ? 1 : chunk.length;
|
||||
|
||||
doWrite(stream, state, false, len, chunk, encoding, cb);
|
||||
entry = entry.next;
|
||||
state.bufferedRequestCount--;
|
||||
// if we didn't call the onwrite immediately, then
|
||||
// it means that we need to wait until it does.
|
||||
// also, that means that the chunk and cb are currently
|
||||
// being processed, so move the buffer counter past them.
|
||||
if (state.writing) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (entry === null) state.lastBufferedRequest = null;
|
||||
}
|
||||
|
||||
state.bufferedRequest = entry;
|
||||
state.bufferProcessing = false;
|
||||
}
|
||||
|
||||
Writable.prototype._write = function (chunk, encoding, cb) {
|
||||
cb(new Error('_write() is not implemented'));
|
||||
};
|
||||
|
||||
Writable.prototype._writev = null;
|
||||
|
||||
Writable.prototype.end = function (chunk, encoding, cb) {
|
||||
var state = this._writableState;
|
||||
|
||||
if (typeof chunk === 'function') {
|
||||
cb = chunk;
|
||||
chunk = null;
|
||||
encoding = null;
|
||||
} else if (typeof encoding === 'function') {
|
||||
cb = encoding;
|
||||
encoding = null;
|
||||
}
|
||||
|
||||
if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
|
||||
|
||||
// .end() fully uncorks
|
||||
if (state.corked) {
|
||||
state.corked = 1;
|
||||
this.uncork();
|
||||
}
|
||||
|
||||
// ignore unnecessary end() calls.
|
||||
if (!state.ending) endWritable(this, state, cb);
|
||||
};
|
||||
|
||||
function needFinish(state) {
|
||||
return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
|
||||
}
|
||||
function callFinal(stream, state) {
|
||||
stream._final(function (err) {
|
||||
state.pendingcb--;
|
||||
if (err) {
|
||||
stream.emit('error', err);
|
||||
}
|
||||
state.prefinished = true;
|
||||
stream.emit('prefinish');
|
||||
finishMaybe(stream, state);
|
||||
});
|
||||
}
|
||||
function prefinish(stream, state) {
|
||||
if (!state.prefinished && !state.finalCalled) {
|
||||
if (typeof stream._final === 'function') {
|
||||
state.pendingcb++;
|
||||
state.finalCalled = true;
|
||||
pna.nextTick(callFinal, stream, state);
|
||||
} else {
|
||||
state.prefinished = true;
|
||||
stream.emit('prefinish');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function finishMaybe(stream, state) {
|
||||
var need = needFinish(state);
|
||||
if (need) {
|
||||
prefinish(stream, state);
|
||||
if (state.pendingcb === 0) {
|
||||
state.finished = true;
|
||||
stream.emit('finish');
|
||||
}
|
||||
}
|
||||
return need;
|
||||
}
|
||||
|
||||
function endWritable(stream, state, cb) {
|
||||
state.ending = true;
|
||||
finishMaybe(stream, state);
|
||||
if (cb) {
|
||||
if (state.finished) pna.nextTick(cb);else stream.once('finish', cb);
|
||||
}
|
||||
state.ended = true;
|
||||
stream.writable = false;
|
||||
}
|
||||
|
||||
function onCorkedFinish(corkReq, state, err) {
|
||||
var entry = corkReq.entry;
|
||||
corkReq.entry = null;
|
||||
while (entry) {
|
||||
var cb = entry.callback;
|
||||
state.pendingcb--;
|
||||
cb(err);
|
||||
entry = entry.next;
|
||||
}
|
||||
|
||||
// reuse the free corkReq.
|
||||
state.corkedRequestsFree.next = corkReq;
|
||||
}
|
||||
|
||||
Object.defineProperty(Writable.prototype, 'destroyed', {
|
||||
get: function () {
|
||||
if (this._writableState === undefined) {
|
||||
return false;
|
||||
}
|
||||
return this._writableState.destroyed;
|
||||
},
|
||||
set: function (value) {
|
||||
// we ignore the value if the stream
|
||||
// has not been initialized yet
|
||||
if (!this._writableState) {
|
||||
return;
|
||||
}
|
||||
|
||||
// backward compatibility, the user is explicitly
|
||||
// managing destroyed
|
||||
this._writableState.destroyed = value;
|
||||
}
|
||||
});
|
||||
|
||||
Writable.prototype.destroy = destroyImpl.destroy;
|
||||
Writable.prototype._undestroy = destroyImpl.undestroy;
|
||||
Writable.prototype._destroy = function (err, cb) {
|
||||
this.end();
|
||||
cb(err);
|
||||
};
|
||||
Generated
Vendored
+78
@@ -0,0 +1,78 @@
|
||||
'use strict';
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var Buffer = require('safe-buffer').Buffer;
|
||||
var util = require('util');
|
||||
|
||||
function copyBuffer(src, target, offset) {
|
||||
src.copy(target, offset);
|
||||
}
|
||||
|
||||
module.exports = function () {
|
||||
function BufferList() {
|
||||
_classCallCheck(this, BufferList);
|
||||
|
||||
this.head = null;
|
||||
this.tail = null;
|
||||
this.length = 0;
|
||||
}
|
||||
|
||||
BufferList.prototype.push = function push(v) {
|
||||
var entry = { data: v, next: null };
|
||||
if (this.length > 0) this.tail.next = entry;else this.head = entry;
|
||||
this.tail = entry;
|
||||
++this.length;
|
||||
};
|
||||
|
||||
BufferList.prototype.unshift = function unshift(v) {
|
||||
var entry = { data: v, next: this.head };
|
||||
if (this.length === 0) this.tail = entry;
|
||||
this.head = entry;
|
||||
++this.length;
|
||||
};
|
||||
|
||||
BufferList.prototype.shift = function shift() {
|
||||
if (this.length === 0) return;
|
||||
var ret = this.head.data;
|
||||
if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
|
||||
--this.length;
|
||||
return ret;
|
||||
};
|
||||
|
||||
BufferList.prototype.clear = function clear() {
|
||||
this.head = this.tail = null;
|
||||
this.length = 0;
|
||||
};
|
||||
|
||||
BufferList.prototype.join = function join(s) {
|
||||
if (this.length === 0) return '';
|
||||
var p = this.head;
|
||||
var ret = '' + p.data;
|
||||
while (p = p.next) {
|
||||
ret += s + p.data;
|
||||
}return ret;
|
||||
};
|
||||
|
||||
BufferList.prototype.concat = function concat(n) {
|
||||
if (this.length === 0) return Buffer.alloc(0);
|
||||
var ret = Buffer.allocUnsafe(n >>> 0);
|
||||
var p = this.head;
|
||||
var i = 0;
|
||||
while (p) {
|
||||
copyBuffer(p.data, ret, i);
|
||||
i += p.data.length;
|
||||
p = p.next;
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
return BufferList;
|
||||
}();
|
||||
|
||||
if (util && util.inspect && util.inspect.custom) {
|
||||
module.exports.prototype[util.inspect.custom] = function () {
|
||||
var obj = util.inspect({ length: this.length });
|
||||
return this.constructor.name + ' ' + obj;
|
||||
};
|
||||
}
|
||||
Generated
Vendored
+84
@@ -0,0 +1,84 @@
|
||||
'use strict';
|
||||
|
||||
/*<replacement>*/
|
||||
|
||||
var pna = require('process-nextick-args');
|
||||
/*</replacement>*/
|
||||
|
||||
// undocumented cb() API, needed for core, not for public API
|
||||
function destroy(err, cb) {
|
||||
var _this = this;
|
||||
|
||||
var readableDestroyed = this._readableState && this._readableState.destroyed;
|
||||
var writableDestroyed = this._writableState && this._writableState.destroyed;
|
||||
|
||||
if (readableDestroyed || writableDestroyed) {
|
||||
if (cb) {
|
||||
cb(err);
|
||||
} else if (err) {
|
||||
if (!this._writableState) {
|
||||
pna.nextTick(emitErrorNT, this, err);
|
||||
} else if (!this._writableState.errorEmitted) {
|
||||
this._writableState.errorEmitted = true;
|
||||
pna.nextTick(emitErrorNT, this, err);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// we set destroyed to true before firing error callbacks in order
|
||||
// to make it re-entrance safe in case destroy() is called within callbacks
|
||||
|
||||
if (this._readableState) {
|
||||
this._readableState.destroyed = true;
|
||||
}
|
||||
|
||||
// if this is a duplex stream mark the writable part as destroyed as well
|
||||
if (this._writableState) {
|
||||
this._writableState.destroyed = true;
|
||||
}
|
||||
|
||||
this._destroy(err || null, function (err) {
|
||||
if (!cb && err) {
|
||||
if (!_this._writableState) {
|
||||
pna.nextTick(emitErrorNT, _this, err);
|
||||
} else if (!_this._writableState.errorEmitted) {
|
||||
_this._writableState.errorEmitted = true;
|
||||
pna.nextTick(emitErrorNT, _this, err);
|
||||
}
|
||||
} else if (cb) {
|
||||
cb(err);
|
||||
}
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
function undestroy() {
|
||||
if (this._readableState) {
|
||||
this._readableState.destroyed = false;
|
||||
this._readableState.reading = false;
|
||||
this._readableState.ended = false;
|
||||
this._readableState.endEmitted = false;
|
||||
}
|
||||
|
||||
if (this._writableState) {
|
||||
this._writableState.destroyed = false;
|
||||
this._writableState.ended = false;
|
||||
this._writableState.ending = false;
|
||||
this._writableState.finalCalled = false;
|
||||
this._writableState.prefinished = false;
|
||||
this._writableState.finished = false;
|
||||
this._writableState.errorEmitted = false;
|
||||
}
|
||||
}
|
||||
|
||||
function emitErrorNT(self, err) {
|
||||
self.emit('error', err);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
destroy: destroy,
|
||||
undestroy: undestroy
|
||||
};
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
module.exports = require('events').EventEmitter;
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
module.exports = require('stream');
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"name": "readable-stream",
|
||||
"version": "2.3.8",
|
||||
"description": "Streams3, a user-land copy of the stream library from Node.js",
|
||||
"main": "readable.js",
|
||||
"dependencies": {
|
||||
"core-util-is": "~1.0.0",
|
||||
"inherits": "~2.0.3",
|
||||
"isarray": "~1.0.0",
|
||||
"process-nextick-args": "~2.0.0",
|
||||
"safe-buffer": "~5.1.1",
|
||||
"string_decoder": "~1.1.1",
|
||||
"util-deprecate": "~1.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"assert": "^1.4.0",
|
||||
"babel-polyfill": "^6.9.1",
|
||||
"buffer": "^4.9.0",
|
||||
"lolex": "^2.3.2",
|
||||
"nyc": "^6.4.0",
|
||||
"tap": "^0.7.0",
|
||||
"tape": "^4.8.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tap test/parallel/*.js test/ours/*.js && node test/verify-dependencies.js",
|
||||
"ci": "tap test/parallel/*.js test/ours/*.js --tap | tee test.tap && node test/verify-dependencies.js",
|
||||
"cover": "nyc npm test",
|
||||
"report": "nyc report --reporter=lcov"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/nodejs/readable-stream"
|
||||
},
|
||||
"keywords": [
|
||||
"readable",
|
||||
"stream",
|
||||
"pipe"
|
||||
],
|
||||
"browser": {
|
||||
"util": false,
|
||||
"./readable.js": "./readable-browser.js",
|
||||
"./writable.js": "./writable-browser.js",
|
||||
"./duplex.js": "./duplex-browser.js",
|
||||
"./lib/internal/streams/stream.js": "./lib/internal/streams/stream-browser.js"
|
||||
},
|
||||
"nyc": {
|
||||
"include": [
|
||||
"lib/**.js"
|
||||
]
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
module.exports = require('./readable').PassThrough
|
||||
Generated
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
exports = module.exports = require('./lib/_stream_readable.js');
|
||||
exports.Stream = exports;
|
||||
exports.Readable = exports;
|
||||
exports.Writable = require('./lib/_stream_writable.js');
|
||||
exports.Duplex = require('./lib/_stream_duplex.js');
|
||||
exports.Transform = require('./lib/_stream_transform.js');
|
||||
exports.PassThrough = require('./lib/_stream_passthrough.js');
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
var Stream = require('stream');
|
||||
if (process.env.READABLE_STREAM === 'disable' && Stream) {
|
||||
module.exports = Stream;
|
||||
exports = module.exports = Stream.Readable;
|
||||
exports.Readable = Stream.Readable;
|
||||
exports.Writable = Stream.Writable;
|
||||
exports.Duplex = Stream.Duplex;
|
||||
exports.Transform = Stream.Transform;
|
||||
exports.PassThrough = Stream.PassThrough;
|
||||
exports.Stream = Stream;
|
||||
} else {
|
||||
exports = module.exports = require('./lib/_stream_readable.js');
|
||||
exports.Stream = Stream || exports;
|
||||
exports.Readable = exports;
|
||||
exports.Writable = require('./lib/_stream_writable.js');
|
||||
exports.Duplex = require('./lib/_stream_duplex.js');
|
||||
exports.Transform = require('./lib/_stream_transform.js');
|
||||
exports.PassThrough = require('./lib/_stream_passthrough.js');
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
module.exports = require('./readable').Transform
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user