-
Notifications
You must be signed in to change notification settings - Fork 22
Sketch of generating zxy streams from S3 sources #56
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
Open
yhahn
wants to merge
9
commits into
master
Choose a base branch
from
zxystream
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
363a193
Sketch of generating zxy streams from S3 sources.
yhahn 94c6121
Add support + tests for {prefix} token
yhahn 5669c65
Drop unused options arg.
yhahn 70c041d
Test + fix createZXYStream
yhahn 4bbadbc
Deps are very important.
yhahn a2a7580
Keep things line-delimited.
yhahn 110c927
Move travis template.
yhahn e1c9890
Merge branch 'doctortest' into zxystream
yhahn 9c76424
Add list permissions for tilelive-s3 prefix.
yhahn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| var util = require('util'); | ||
| var split = require('split'); | ||
| var s3scan = require('s3scan'); | ||
| var s3urls = require('s3urls'); | ||
| var StreamConcat = require('stream-concat'); | ||
|
|
||
| module.exports = ZXYStream; | ||
| module.exports.config = config; | ||
|
|
||
| function ZXYStream(tilesUrl) { | ||
| var conf = config(tilesUrl); | ||
| var current = 0; | ||
| return new StreamConcat(function() { | ||
| if (!conf.toList[current]) return null; | ||
| return s3scan.List(conf.toList[current++], {}) | ||
| }).pipe(split(function(line) { | ||
| var matches = line.match(conf.tokenPattern); | ||
| if (!matches || matches.length < 4) return undefined; | ||
| return matches[conf.tokenMap[0]] + '/' + | ||
| matches[conf.tokenMap[1]] + '/' + | ||
| matches[conf.tokenMap[2]] + '\n'; | ||
| })); | ||
| } | ||
|
|
||
| function config(tilesUrl) { | ||
| var conf = {}; | ||
| conf.toList = []; | ||
| if ((/{prefix}/).test(tilesUrl)) { | ||
| for (var i = 0; i < 256; i++) { | ||
| var prefix = i < 16 ? '0' + i.toString(16) : i.toString(16); | ||
| conf.toList.push(s3urls.convert(tilesUrl, 's3').split(/{(z|x|y)}/)[0].replace(/{prefix}/g,prefix)); | ||
| } | ||
| } else { | ||
| conf.toList.push(s3urls.convert(tilesUrl, 's3').split(/{(z|x|y)}/)[0]); | ||
| } | ||
|
|
||
| var matches = s3urls.fromUrl(tilesUrl).Key.match(/{(z|x|y)}/g); | ||
| if (matches.length !== 3) throw new Error('Could not find {z}, {x} and {y} tokens in url: ' + tilesUrl); | ||
|
|
||
| conf.tokenMap = matches.reduce(function(memo, token, i) { | ||
| if (token === '{z}') { | ||
| memo[i] = 1; | ||
| } else if (token === '{x}') { | ||
| memo[i] = 2; | ||
| } else if (token === '{y}') { | ||
| memo[i] = 3; | ||
| } | ||
| return memo; | ||
| }, []); | ||
|
|
||
| conf.tokenPattern = new RegExp(s3urls.fromUrl(tilesUrl).Key | ||
| .replace(/{prefix}/g, '[0-f]{2}') | ||
| .replace(/{(z|x|y)}/g, '([0-9]+)')); | ||
|
|
||
| return conf; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a branch of s3scan lurking somewhere that could navigate 2-char hex
{prefix}s in urls. Would you prefer to keep the logic here in tilelive-s3, or do you think it would be broadly useful there?