Skip to content

Commit ea7ebb0

Browse files
authored
Merge pull request #1208 from appwrite/fix-flutter-chunk-size-constant-naming
Fix Flutter constant naming: CHUNK_SIZE to chunkSize
2 parents 10e7d6c + 6a38a32 commit ea7ebb0

File tree

6 files changed

+30
-30
lines changed

6 files changed

+30
-30
lines changed

templates/dart/lib/src/client.dart.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import 'upload_progress.dart';
77

88
/// [Client] that handles requests to {{spec.title | caseUcfirst}}
99
abstract class Client {
10-
/// The size for cunked uploads in bytes.
11-
static const int CHUNK_SIZE = 5 * 1024 * 1024;
10+
/// The size for chunked uploads in bytes.
11+
static const int chunkSize = 5 * 1024 * 1024;
1212

1313
/// Holds configuration such as project.
1414
late Map<String, String> config;

templates/dart/lib/src/client_browser.dart.twig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ClientBase createClient({
1616
ClientBrowser(endPoint: endPoint, selfSigned: selfSigned);
1717

1818
class ClientBrowser extends ClientBase with ClientMixin {
19-
static const int CHUNK_SIZE = 5*1024*1024;
19+
static const int chunkSize = 5*1024*1024;
2020
String _endPoint;
2121
Map<String, String>? _headers;
2222
@override
@@ -106,7 +106,7 @@ class ClientBrowser extends ClientBase with ClientMixin {
106106
int size = file.bytes!.length;
107107

108108
late Response res;
109-
if (size <= CHUNK_SIZE) {
109+
if (size <= chunkSize) {
110110
params[paramName] = http.MultipartFile.fromBytes(paramName, file.bytes!, filename: file.filename);
111111
return call(
112112
HttpMethod.post,
@@ -126,21 +126,21 @@ class ClientBrowser extends ClientBase with ClientMixin {
126126
headers: headers,
127127
);
128128
final int chunksUploaded = res.data['chunksUploaded'] as int;
129-
offset = chunksUploaded * CHUNK_SIZE;
129+
offset = chunksUploaded * chunkSize;
130130
} on {{spec.title | caseUcfirst}}Exception catch (_) {}
131131
}
132132

133133
while (offset < size) {
134134
List<int> chunk = [];
135-
final end = min(offset + CHUNK_SIZE, size);
135+
final end = min(offset + chunkSize, size);
136136
chunk = file.bytes!.getRange(offset, end).toList();
137137
params[paramName] =
138138
http.MultipartFile.fromBytes(paramName, chunk, filename: file.filename);
139139
headers['content-range'] =
140-
'bytes $offset-${min<int>((offset + CHUNK_SIZE - 1), size - 1)}/$size';
140+
'bytes $offset-${min<int>((offset + chunkSize - 1), size - 1)}/$size';
141141
res = await call(HttpMethod.post,
142142
path: path, headers: headers, params: params);
143-
offset += CHUNK_SIZE;
143+
offset += chunkSize;
144144
if (offset < size) {
145145
headers['x-{{spec.title | caseLower }}-id'] = res.data['\$id'];
146146
}

templates/dart/lib/src/client_io.dart.twig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ClientBase createClient({
2020
);
2121

2222
class ClientIO extends ClientBase with ClientMixin {
23-
static const int CHUNK_SIZE = 5*1024*1024;
23+
static const int chunkSize = 5*1024*1024;
2424
String _endPoint;
2525
Map<String, String>? _headers;
2626
@override
@@ -120,7 +120,7 @@ class ClientIO extends ClientBase with ClientMixin {
120120
}
121121

122122
late Response res;
123-
if (size <= CHUNK_SIZE) {
123+
if (size <= chunkSize) {
124124
if (file.path != null) {
125125
params[paramName] = await http.MultipartFile.fromPath(
126126
paramName, file.path!,
@@ -147,7 +147,7 @@ class ClientIO extends ClientBase with ClientMixin {
147147
headers: headers,
148148
);
149149
final int chunksUploaded = res.data['chunksUploaded'] as int;
150-
offset = chunksUploaded * CHUNK_SIZE;
150+
offset = chunksUploaded * chunkSize;
151151
} on {{spec.title | caseUcfirst}}Exception catch (_) {}
152152
}
153153

@@ -160,19 +160,19 @@ class ClientIO extends ClientBase with ClientMixin {
160160
while (offset < size) {
161161
List<int> chunk = [];
162162
if (file.bytes != null) {
163-
final end = min(offset + CHUNK_SIZE, size);
163+
final end = min(offset + chunkSize, size);
164164
chunk = file.bytes!.getRange(offset, end).toList();
165165
} else {
166166
raf!.setPositionSync(offset);
167-
chunk = raf.readSync(CHUNK_SIZE);
167+
chunk = raf.readSync(chunkSize);
168168
}
169169
params[paramName] =
170170
http.MultipartFile.fromBytes(paramName, chunk, filename: file.filename);
171171
headers['content-range'] =
172-
'bytes $offset-${min<int>((offset + CHUNK_SIZE - 1), size - 1)}/$size';
172+
'bytes $offset-${min<int>((offset + chunkSize - 1), size - 1)}/$size';
173173
res = await call(HttpMethod.post,
174174
path: path, headers: headers, params: params);
175-
offset += CHUNK_SIZE;
175+
offset += chunkSize;
176176
if (offset < size) {
177177
headers['x-{{spec.title | caseLower }}-id'] = res.data['\$id'];
178178
}

templates/flutter/lib/src/client.dart.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import 'upload_progress.dart';
99
///
1010
/// The [Client] is also responsible for managing user's sessions.
1111
abstract class Client {
12-
/// The size for cunked uploads in bytes.
13-
static const int CHUNK_SIZE = 5 * 1024 * 1024;
12+
/// The size for chunked uploads in bytes.
13+
static const int chunkSize = 5 * 1024 * 1024;
1414

1515
/// Holds configuration such as project.
1616
late Map<String, String> config;

templates/flutter/lib/src/client_browser.dart.twig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ClientBase createClient({required String endPoint, required bool selfSigned}) =>
1616
ClientBrowser(endPoint: endPoint, selfSigned: selfSigned);
1717

1818
class ClientBrowser extends ClientBase with ClientMixin {
19-
static const int CHUNK_SIZE = 5 * 1024 * 1024;
19+
static const int chunkSize = 5 * 1024 * 1024;
2020
String _endPoint;
2121
Map<String, String>? _headers;
2222
@override
@@ -130,7 +130,7 @@ class ClientBrowser extends ClientBase with ClientMixin {
130130
int size = file.bytes!.length;
131131

132132
late Response res;
133-
if (size <= CHUNK_SIZE) {
133+
if (size <= chunkSize) {
134134
params[paramName] = http.MultipartFile.fromBytes(
135135
paramName,
136136
file.bytes!,
@@ -154,28 +154,28 @@ class ClientBrowser extends ClientBase with ClientMixin {
154154
headers: headers,
155155
);
156156
final int chunksUploaded = res.data['chunksUploaded'] as int;
157-
offset = chunksUploaded * CHUNK_SIZE;
157+
offset = chunksUploaded * chunkSize;
158158
} on {{spec.title | caseUcfirst}}Exception catch (_) {}
159159
}
160160

161161
while (offset < size) {
162162
List<int> chunk = [];
163-
final end = min(offset + CHUNK_SIZE, size);
163+
final end = min(offset + chunkSize, size);
164164
chunk = file.bytes!.getRange(offset, end).toList();
165165
params[paramName] = http.MultipartFile.fromBytes(
166166
paramName,
167167
chunk,
168168
filename: file.filename,
169169
);
170170
headers['content-range'] =
171-
'bytes $offset-${min<int>((offset + CHUNK_SIZE - 1), size - 1)}/$size';
171+
'bytes $offset-${min<int>((offset + chunkSize - 1), size - 1)}/$size';
172172
res = await call(
173173
HttpMethod.post,
174174
path: path,
175175
headers: headers,
176176
params: params,
177177
);
178-
offset += CHUNK_SIZE;
178+
offset += chunkSize;
179179
if (offset < size) {
180180
headers['x-{{spec.title | caseLower }}-id'] = res.data['\$id'];
181181
}

templates/flutter/lib/src/client_io.dart.twig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ ClientBase createClient({required String endPoint, required bool selfSigned}) =>
2222
ClientIO(endPoint: endPoint, selfSigned: selfSigned);
2323

2424
class ClientIO extends ClientBase with ClientMixin {
25-
static const int CHUNK_SIZE = 5 * 1024 * 1024;
25+
static const int chunkSize = 5 * 1024 * 1024;
2626
String _endPoint;
2727
Map<String, String>? _headers;
2828
@override
@@ -244,7 +244,7 @@ class ClientIO extends ClientBase with ClientMixin {
244244
}
245245

246246
late Response res;
247-
if (size <= CHUNK_SIZE) {
247+
if (size <= chunkSize) {
248248
if (file.path != null) {
249249
params[paramName] = await http.MultipartFile.fromPath(
250250
paramName,
@@ -276,7 +276,7 @@ class ClientIO extends ClientBase with ClientMixin {
276276
headers: headers,
277277
);
278278
final int chunksUploaded = res.data['chunksUploaded'] as int;
279-
offset = chunksUploaded * CHUNK_SIZE;
279+
offset = chunksUploaded * chunkSize;
280280
} on {{spec.title | caseUcfirst}}Exception catch (_) {}
281281
}
282282

@@ -289,26 +289,26 @@ class ClientIO extends ClientBase with ClientMixin {
289289
while (offset < size) {
290290
List<int> chunk = [];
291291
if (file.bytes != null) {
292-
final end = min(offset + CHUNK_SIZE, size);
292+
final end = min(offset + chunkSize, size);
293293
chunk = file.bytes!.getRange(offset, end).toList();
294294
} else {
295295
raf!.setPositionSync(offset);
296-
chunk = raf.readSync(CHUNK_SIZE);
296+
chunk = raf.readSync(chunkSize);
297297
}
298298
params[paramName] = http.MultipartFile.fromBytes(
299299
paramName,
300300
chunk,
301301
filename: file.filename,
302302
);
303303
headers['content-range'] =
304-
'bytes $offset-${min<int>((offset + CHUNK_SIZE - 1), size - 1)}/$size';
304+
'bytes $offset-${min<int>((offset + chunkSize - 1), size - 1)}/$size';
305305
res = await call(
306306
HttpMethod.post,
307307
path: path,
308308
headers: headers,
309309
params: params,
310310
);
311-
offset += CHUNK_SIZE;
311+
offset += chunkSize;
312312
if (offset < size) {
313313
headers['x-{{spec.title | caseLower }}-id'] = res.data['\$id'];
314314
}

0 commit comments

Comments
 (0)