birdpack 1.0.12 → 1.0.14

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/lib/core.js CHANGED
@@ -328,6 +328,8 @@ module.exports = class{
328
328
  fileRange = 'stream';
329
329
  }
330
330
  options.type = fileType[fileExt];
331
+ }else{
332
+ options.type = 'application';
331
333
  }
332
334
 
333
335
  if(options.stream === true){
@@ -338,54 +340,41 @@ module.exports = class{
338
340
  const totalSize = fileStat.size;
339
341
  let match = (this.get('range') || '').slice(6).split('-');
340
342
 
341
- this.set('accept-ranges', 'bytes')
342
- .type(options.type);
343
+ const start = parseInt(match[0], 10) || 0;
344
+ const end = parseInt(match[1], 10) || totalSize - 1;
343
345
 
344
- if(match.length == 2){
345
- const start = parseInt(match[0], 10) || 0;
346
- const end = parseInt(match[1], 10) || totalSize - 1;
346
+ const chunkSize = end - start + 1;
347
+ const fileDescriptor = fs.openSync(options.file, "r");
347
348
 
348
- const chunkSize = end - start + 1;
349
- const fileDescriptor = fs.openSync(options.file, "r");
350
-
351
- const sendChunk = (position) => {
352
- if(position > end){
353
- fs.closeSync(fileDescriptor);
354
- return;
355
- }
349
+ const sendChunk = (position) => {
350
+ if(position > end){
351
+ fs.closeSync(fileDescriptor);
352
+ return;
353
+ }
356
354
 
357
- const bytesToRead = Math.min(bufferSize, end - position + 1);
358
- const bytesRead = fs.readSync(fileDescriptor, buffer, 0, bytesToRead, position);
355
+ const bytesToRead = Math.min(bufferSize, end - position + 1);
356
+ const bytesRead = fs.readSync(fileDescriptor, buffer, 0, bytesToRead, position);
359
357
 
360
- if(bytesRead > 0 && this.res.writable){
361
- this[position + bytesRead > end ? 'end' : 'write'](buffer.slice(0, bytesRead), (err) => {
362
- if(err){
363
- fs.closeSync(fileDescriptor);
364
- }else{
365
- sendChunk(position + bytesRead);
366
- }
367
- });
368
- }else{
369
- fs.closeSync(fileDescriptor);
370
- }
371
- };
372
-
373
- this.code(206)
374
- .length(chunkSize)
375
- .set('content-range', `bytes ${start}-${end}/${totalSize}`)
376
- .writeHead();
377
- sendChunk(start);
378
- }else{
379
- const start = 0;
380
- const end = totalSize - 1;
381
- const chunkSize = end - start + 1;
382
-
383
- this.code(200)
384
- .length(chunkSize)
385
- .set('content-range', `bytes ${start}-${end}/${totalSize}`)
386
- .writeHead();
387
- this.end();
388
- }
358
+ if(bytesRead > 0 && this.res.writable){
359
+ this[position + bytesRead > end ? 'end' : 'write'](buffer.slice(0, bytesRead), (err) => {
360
+ if(err){
361
+ fs.closeSync(fileDescriptor);
362
+ }else{
363
+ sendChunk(position + bytesRead);
364
+ }
365
+ });
366
+ }else{
367
+ fs.closeSync(fileDescriptor);
368
+ }
369
+ };
370
+
371
+ this.code(206)
372
+ .length(chunkSize)
373
+ .type(options.type)
374
+ .set('accept-ranges', 'bytes')
375
+ .set('content-range', `bytes ${start}-${end}/${totalSize}`)
376
+ .writeHead();
377
+ sendChunk(start);
389
378
  }else if(fileRange == 'file'){
390
379
  if(options.parameter){
391
380
  let data = fs.readFileSync(options.file, { encoding: 'utf8', flag: 'r' });
package/lib/method.js CHANGED
@@ -28,7 +28,9 @@ const serviceMethod = {
28
28
  }
29
29
  },
30
30
  directory:(use)=>{
31
- return (dir, {path, callback, error})=>{
31
+ return (dir, option)=>{
32
+ let {path, callback, error} = option || {};
33
+
32
34
  if(typeof path !== 'string'){
33
35
  path = '/';
34
36
  }else if(path[path.length-1] != '/'){
package/lib/server.js CHANGED
@@ -334,7 +334,12 @@ module.exports = class{
334
334
  return config;
335
335
  }
336
336
  set({domain, method, url, next, callback}){
337
- if(typeof domain != 'string'){
337
+ if(Array.isArray(domain)){
338
+ for(let x of domain){
339
+ this.set({domain:x, method, url, next, callback});
340
+ }
341
+ return true;
342
+ }else if(typeof domain != 'string'){
338
343
  domain = '*';
339
344
  }
340
345
 
@@ -383,7 +388,12 @@ module.exports = class{
383
388
  }
384
389
  }
385
390
  setUpgrade({domain, next, url, callback}){
386
- if(typeof domain != 'string'){
391
+ if(Array.isArray(domain)){
392
+ for(let x of domain){
393
+ this.set({domain:x, next, url, callback});
394
+ }
395
+ return true;
396
+ }else if(typeof domain != 'string'){
387
397
  domain = '*';
388
398
  }
389
399
 
package/package.json CHANGED
@@ -3,6 +3,6 @@
3
3
  "description": "BirdPack web framework is a tool for web server via TCP HTTP supporting websocket focusing on speed.",
4
4
  "author":"R938",
5
5
  "license":"R938",
6
- "version":"1.0.12",
6
+ "version":"1.0.14",
7
7
  "main": "index.js"
8
8
  }