files.com 1.0.256 → 1.0.258
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/_VERSION +1 -1
- package/lib/isomorphic/File.node.js +39 -9
- package/lib/models/File.js +303 -277
- package/package.json +1 -1
- package/shared/normalization_for_comparison_test_data.json +38 -0
- package/src/isomorphic/File.node.js +14 -0
- package/src/models/File.js +15 -0
- package/test/src/index.js +34 -3
package/package.json
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
[
|
2
|
+
[ "filename.txt", "filename.txt" ],
|
3
|
+
[ "FiLeNaMe.TxT", "filename.txt" ],
|
4
|
+
[ "FILENAME.TXT", "filename.txt" ],
|
5
|
+
[ "FÎŁĘÑÂMÉ.TXT", "filename.txt" ],
|
6
|
+
[ "Fïłèńämê.Txt", "filename.txt" ],
|
7
|
+
[ "a/b/c.txt", "a/b/c.txt" ],
|
8
|
+
[ "A\\B\\C.TXT", "a/b/c.txt" ],
|
9
|
+
[ "A/B\\C.TXT", "a/b/c.txt" ],
|
10
|
+
[ "//a/b//c.txt", "a/b/c.txt" ],
|
11
|
+
[ "a/b/c.txt ", "a/b/c.txt" ],
|
12
|
+
[ "a/b/c.txt\t", "a/b/c.txt" ],
|
13
|
+
[ "a/b/c.txt\n", "a/b/c.txt" ],
|
14
|
+
[ "a/b/c.txt\r", "a/b/c.txt" ],
|
15
|
+
[ " space_at_beginning", " space_at_beginning"],
|
16
|
+
[ "space_at_end ", "space_at_end"],
|
17
|
+
[ "tab\tseperated", "tab\tseperated"],
|
18
|
+
[ "<title>hello</hello>", "<title>hello</hello>"],
|
19
|
+
[ "안녕하세요", "안녕하세요" ],
|
20
|
+
[ "こんにちは", "こんにちは" ],
|
21
|
+
[ "今日は", "今日は" ],
|
22
|
+
[ "longest_unicode_character_﷽", "longest_unicode_character_﷽"],
|
23
|
+
[ "invalid_null_byte_before\u0000after", "invalid_null_byte_beforeafter" ],
|
24
|
+
[ "a/b/c/../../hello", "a/b/c/hello" ],
|
25
|
+
[ "a/b/c/././hello", "a/b/c/hello" ],
|
26
|
+
[ "one_code_point_ą", "one_code_point_a" ],
|
27
|
+
[ "two_code_points_ą", "two_code_points_a" ],
|
28
|
+
[ "one_code_point_훯", "one_code_point_훯"],
|
29
|
+
[ "three_code_points_훯", "three_code_points_훯" ],
|
30
|
+
[ "ÞþŊŋŦŧ", "þþŋŋŧŧ" ],
|
31
|
+
[ "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ", "aaaaaaaeceeeeiiiidnoooooouuuuyssaaaaaaaeceeeeiiiidnoooooouuuuyy" ],
|
32
|
+
[ "ĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİIJij", "aaaaaaccccccccddddeeeeeeeeeegggggggghhhhiiiiiiiiiijij" ],
|
33
|
+
[ "ĴĵĶķĹĺĻļĽľŁłŃńŅņŇňʼnŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤť", "jjkkllllllllnnnnnnʼnoooooooeoerrrrrrsssssssstttt" ],
|
34
|
+
[ "ŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽž", "uuuuuuuuuuuuwwyyyzzzzzz" ],
|
35
|
+
[ "😂❤️😍🤣😊🙏💕😭😘👍😅👏😁♥️🔥💔💖💙😢🤔😆🙄💪😉☺️👌🤗", "😂❤️😍🤣😊🙏💕😭😘👍😅👏😁♥️🔥💔💖💙😢🤔😆🙄💪😉☺️👌🤗" ],
|
36
|
+
[ "💜😔😎😇🌹🤦🎉💞✌️✨🤷😱😌🌸🙌😋💗💚😏💛🙂💓🤩😄😀🖤😃💯🙈👇🎶😒🤭❣️", "💜😔😎😇🌹🤦🎉💞✌️✨🤷😱😌🌸🙌😋💗💚😏💛🙂💓🤩😄😀🖤😃💯🙈👇🎶😒🤭❣️" ],
|
37
|
+
[ "emoji_‼️", "emoji_!!️" ]
|
38
|
+
]
|
@@ -21,6 +21,19 @@ const saveUrlToStream = async (url, stream) => new Promise((resolve, reject) =>
|
|
21
21
|
})
|
22
22
|
})
|
23
23
|
|
24
|
+
const saveUrlToString = async url => new Promise((resolve, reject) => {
|
25
|
+
const https = require('https')
|
26
|
+
|
27
|
+
https.get(url, response => {
|
28
|
+
const chunks = []
|
29
|
+
response.on('data', chunk => chunks.push(Buffer.from(chunk)))
|
30
|
+
response.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')))
|
31
|
+
})
|
32
|
+
.on('error', error => {
|
33
|
+
reject(error)
|
34
|
+
})
|
35
|
+
})
|
36
|
+
|
24
37
|
const saveUrlToFile = async (url, destinationPath) => {
|
25
38
|
const stream = openDiskFileWriteStream(destinationPath)
|
26
39
|
await saveUrlToStream(url, stream)
|
@@ -32,4 +45,5 @@ export {
|
|
32
45
|
openDiskFileWriteStream,
|
33
46
|
saveUrlToFile,
|
34
47
|
saveUrlToStream,
|
48
|
+
saveUrlToString,
|
35
49
|
}
|
package/src/models/File.js
CHANGED
@@ -199,6 +199,21 @@ class File {
|
|
199
199
|
return saveUrlToStream(downloadUri, writableStream)
|
200
200
|
}
|
201
201
|
|
202
|
+
downloadToString = async () => {
|
203
|
+
if (isBrowser()) {
|
204
|
+
throw new errors.NotImplementedError('String downloads are only available in a NodeJS environment')
|
205
|
+
}
|
206
|
+
|
207
|
+
const downloadUri = this.getDownloadUri()
|
208
|
+
|
209
|
+
if (!downloadUri) {
|
210
|
+
throw new errors.EmptyPropertyError('Current object has no download URI')
|
211
|
+
}
|
212
|
+
|
213
|
+
const { saveUrlToString } = require('../isomorphic/File.node.js')
|
214
|
+
return saveUrlToString(downloadUri)
|
215
|
+
}
|
216
|
+
|
202
217
|
downloadToFile = async destinationPath => {
|
203
218
|
if (isBrowser()) {
|
204
219
|
throw new errors.NotImplementedError('Disk file downloads are only available in a NodeJS environment')
|
package/test/src/index.js
CHANGED
@@ -64,7 +64,7 @@ const testSuite = async () => {
|
|
64
64
|
Logger.info('***** testFolderListAutoPagination() succeeded! *****')
|
65
65
|
}
|
66
66
|
|
67
|
-
const
|
67
|
+
const testUploadAndDownloadToFile = async () => {
|
68
68
|
const sourceFilePath = '../files.com-logo.png'
|
69
69
|
|
70
70
|
const displayName = `files.com-logo__${nonce}.png`
|
@@ -99,7 +99,37 @@ const testSuite = async () => {
|
|
99
99
|
|
100
100
|
await file.delete()
|
101
101
|
|
102
|
-
Logger.info('*****
|
102
|
+
Logger.info('***** testUploadAndDownloadToFile() succeeded! *****')
|
103
|
+
}
|
104
|
+
|
105
|
+
const testUploadAndDownloadToString = async () => {
|
106
|
+
const displayName = `test-text__${nonce}.txt`
|
107
|
+
const destinationPath = `${SDK_TEST_ROOT_FOLDER}/${displayName}`
|
108
|
+
|
109
|
+
const sourceFileContents = 'The quick brown fox jumped over the lazy dogs.'
|
110
|
+
const file = await File.uploadData(destinationPath, sourceFileContents)
|
111
|
+
|
112
|
+
assert(!!file.path)
|
113
|
+
assert(file.display_name === displayName)
|
114
|
+
|
115
|
+
const foundFile = await File.find(destinationPath)
|
116
|
+
|
117
|
+
assert(foundFile.path === destinationPath)
|
118
|
+
assert(foundFile.display_name === displayName)
|
119
|
+
assert(typeof foundFile.getDownloadUri() === 'undefined')
|
120
|
+
|
121
|
+
if (!isBrowser()) {
|
122
|
+
const downloadableFile = await foundFile.download()
|
123
|
+
assert(typeof downloadableFile.getDownloadUri() !== 'undefined')
|
124
|
+
|
125
|
+
const downloadedFileContents = await downloadableFile.downloadToString()
|
126
|
+
|
127
|
+
assert(sourceFileContents === downloadedFileContents)
|
128
|
+
}
|
129
|
+
|
130
|
+
await file.delete()
|
131
|
+
|
132
|
+
Logger.info('***** testUploadAndDownloadToString() succeeded! *****')
|
103
133
|
}
|
104
134
|
|
105
135
|
/* to run this test, put a file (or symlink) at huge-file.ext * /
|
@@ -200,7 +230,8 @@ const testSuite = async () => {
|
|
200
230
|
//
|
201
231
|
|
202
232
|
await testFolderListAutoPagination()
|
203
|
-
await
|
233
|
+
await testUploadAndDownloadToFile()
|
234
|
+
await testUploadAndDownloadToString()
|
204
235
|
// await testUploadHugeFile() // to run this test, put a file (or symlink) at huge-file.ext
|
205
236
|
await testSession()
|
206
237
|
await testFailure()
|