Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix path handling on win32 systems #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/write-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,21 @@ module.exports = function createWriteStream(root, options) {
contentType = mime.lookup(name);
}

var posixRelative = file.relative;
if (path.sep == '\\') {
// on win32 replace all backslashes with the slashes that S3 expects as path separators
posixRelative = posixRelative.replace(/\\/g,'/')
}
var fileOptions = _.assign({ }, awsOptions, {
Key: prefix + file.relative,
Key: path.posix.normalize(prefix + posixRelative),
ContentType: contentType
}, file.awsOptions);

// consider: correct for normalization failure, e.g. fileOptions.Key starts with "../"
// which would mean that next write will fail anyway (due to apparent undocumented S3 rule
// that you can't have a folder on a bucket root called "..", and also that S3 reads ".."
// literally, not as a symbol for a parent folder).

if (contentEncoding.length > 0) {
_.assign(fileOptions, {
ContentEncoding: contentEncoding.join(',')
Expand Down