@jupyterlite/contents 0.1.0-beta.12 → 0.1.0-beta.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/contents.js CHANGED
@@ -273,9 +273,9 @@ export class Contents {
273
273
  }
274
274
  if (!(options === null || options === void 0 ? void 0 : options.content)) {
275
275
  return {
276
+ size: 0,
276
277
  ...model,
277
278
  content: null,
278
- size: 0,
279
279
  };
280
280
  }
281
281
  // for directories, find all files with the path as the prefix
@@ -377,27 +377,42 @@ export class Contents {
377
377
  };
378
378
  if (options.content && options.format === 'base64') {
379
379
  if (ext === '.ipynb') {
380
+ const contentUnescaped = this.unescapeContent(options.content);
381
+ const size = contentUnescaped.length;
380
382
  item = {
381
383
  ...item,
382
- content: JSON.parse(this.unescapeContent(options.content)),
384
+ content: JSON.parse(contentUnescaped),
383
385
  format: 'json',
384
386
  type: 'notebook',
387
+ size: size,
385
388
  };
386
389
  }
387
390
  else if (FILE.hasFormat(ext, 'json')) {
391
+ const contentUnescaped = this.unescapeContent(options.content);
392
+ const size = contentUnescaped.length;
388
393
  item = {
389
394
  ...item,
390
- content: JSON.parse(this.unescapeContent(options.content)),
395
+ content: JSON.parse(contentUnescaped),
391
396
  format: 'json',
392
397
  type: 'file',
398
+ size: size,
393
399
  };
394
400
  }
395
401
  else if (FILE.hasFormat(ext, 'text')) {
402
+ const contentUnescaped = this.unescapeContent(options.content);
403
+ const size = contentUnescaped.length;
396
404
  item = {
397
405
  ...item,
398
- content: this.unescapeContent(options.content),
406
+ content: contentUnescaped,
399
407
  format: 'text',
400
408
  type: 'file',
409
+ size: size,
410
+ };
411
+ }
412
+ else {
413
+ item = {
414
+ ...item,
415
+ size: atob(options.content).length,
401
416
  };
402
417
  }
403
418
  }
@@ -563,7 +578,8 @@ export class Contents {
563
578
  mimetype: MIME.PLAIN_TEXT,
564
579
  type: 'file',
565
580
  writable: true,
566
- content: null,
581
+ size: 0,
582
+ content: '',
567
583
  };
568
584
  if (options === null || options === void 0 ? void 0 : options.content) {
569
585
  if (model.type === 'directory') {
@@ -582,27 +598,34 @@ export class Contents {
582
598
  FILE.hasFormat(ext, 'json') ||
583
599
  (mimetype === null || mimetype === void 0 ? void 0 : mimetype.indexOf('json')) !== -1 ||
584
600
  path.match(/\.(ipynb|[^/]*json[^/]*)$/)) {
601
+ const contentText = await response.text();
585
602
  model = {
586
603
  ...model,
587
- content: await response.json(),
604
+ content: JSON.parse(contentText),
588
605
  format: 'json',
589
606
  mimetype: model.mimetype || MIME.JSON,
607
+ size: contentText.length,
590
608
  };
591
609
  }
592
610
  else if (FILE.hasFormat(ext, 'text') || mimetype.indexOf('text') !== -1) {
611
+ const contentText = await response.text();
593
612
  model = {
594
613
  ...model,
595
- content: await response.text(),
614
+ content: contentText,
596
615
  format: 'text',
597
616
  mimetype: mimetype || MIME.PLAIN_TEXT,
617
+ size: contentText.length,
598
618
  };
599
619
  }
600
620
  else {
621
+ const contentBytes = await response.arrayBuffer();
622
+ const contentBuffer = new Uint8Array(contentBytes);
601
623
  model = {
602
624
  ...model,
603
- content: btoa(new Uint8Array(await response.arrayBuffer()).reduce(this.reduceBytesToString, '')),
625
+ content: btoa(contentBuffer.reduce(this.reduceBytesToString, '')),
604
626
  format: 'base64',
605
627
  mimetype: mimetype || MIME.OCTET_STREAM,
628
+ size: contentBuffer.length,
606
629
  };
607
630
  }
608
631
  }
package/lib/drivefs.d.ts CHANGED
@@ -37,6 +37,7 @@ export interface IStats {
37
37
  timestamp?: number;
38
38
  }
39
39
  export interface IEmscriptenFSNode {
40
+ id: number;
40
41
  name: string;
41
42
  mode: number;
42
43
  parent: IEmscriptenFSNode;
package/lib/drivefs.js CHANGED
@@ -122,7 +122,11 @@ export class DriveFSEmscriptenNodeOps {
122
122
  this.fs = fs;
123
123
  }
124
124
  getattr(node) {
125
- return this.fs.API.getattr(this.fs.realPath(node));
125
+ return {
126
+ ...this.fs.API.getattr(this.fs.realPath(node)),
127
+ mode: node.mode,
128
+ ino: node.id,
129
+ };
126
130
  }
127
131
  setattr(node, attr) {
128
132
  // TODO
@@ -277,11 +281,15 @@ export class ContentsAPI {
277
281
  }
278
282
  }
279
283
  getattr(path) {
280
- const stats = this.request({ method: 'getattr', path: this.normalizePath(path) });
284
+ const stats = this.request({
285
+ method: 'getattr',
286
+ path: this.normalizePath(path),
287
+ });
281
288
  // Turn datetimes into proper objects
282
289
  stats.atime = new Date(stats.atime);
283
290
  stats.mtime = new Date(stats.mtime);
284
291
  stats.ctime = new Date(stats.ctime);
292
+ // ensure a non-undefined size (0 isn't great, though)
285
293
  stats.size = stats.size || 0;
286
294
  return stats;
287
295
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyterlite/contents",
3
- "version": "0.1.0-beta.12",
3
+ "version": "0.1.0-beta.14",
4
4
  "description": "JupyterLite - Contents",
5
5
  "homepage": "https://github.com/jupyterlite/jupyterlite",
6
6
  "bugs": {
@@ -42,9 +42,9 @@
42
42
  "watch": "tsc -b --watch"
43
43
  },
44
44
  "dependencies": {
45
- "@jupyterlab/nbformat": "~3.4.5",
46
- "@jupyterlab/services": "~6.4.5",
47
- "@jupyterlite/localforage": "^0.1.0-beta.12",
45
+ "@jupyterlab/nbformat": "~3.4.8",
46
+ "@jupyterlab/services": "~6.4.6",
47
+ "@jupyterlite/localforage": "^0.1.0-beta.14",
48
48
  "@lumino/coreutils": "^1.12.0",
49
49
  "localforage": "^1.9.0",
50
50
  "mime": "^3.0.0"
@@ -52,7 +52,7 @@
52
52
  "devDependencies": {
53
53
  "@babel/core": "^7.11.6",
54
54
  "@babel/preset-env": "^7.12.1",
55
- "@jupyterlab/testutils": "~3.4.5",
55
+ "@jupyterlab/testutils": "~3.4.8",
56
56
  "@types/jest": "^26.0.10",
57
57
  "@types/mime": "^2.0.3",
58
58
  "jest": "^26.4.2",