@leofcoin/peernet 0.13.3 → 0.13.4

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.
@@ -9978,7 +9978,7 @@ class Peernet {
9978
9978
  return hash
9979
9979
  }
9980
9980
 
9981
- async ls(hash) {
9981
+ async ls(hash, options) {
9982
9982
  let data
9983
9983
  const has = await dataStore.has(hash)
9984
9984
  if (has) data = await dataStore.get(hash)
@@ -9990,18 +9990,19 @@ class Peernet {
9990
9990
  for (const {path, hash} of node.decoded.links) {
9991
9991
  paths.push({path, hash})
9992
9992
  }
9993
-
9993
+ if (options?.pin) await dataStore.put(hash, node.encoded)
9994
9994
  return paths
9995
9995
  }
9996
9996
 
9997
- async cat(hash) {
9997
+ async cat(hash, options) {
9998
9998
  let data
9999
9999
  const has = await dataStore.has(hash)
10000
10000
  if (has) data = await dataStore.get(hash)
10001
10001
  else data = await this.requestData(hash, 'data')
10002
10002
  const node = await new peernet.protos['peernet-file'](data)
10003
- const paths = []
10003
+
10004
10004
  if (node.decoded?.links.length > 0) throw new Error(`${hash} is a directory`)
10005
+ if (options?.pin) await dataStore.put(hash, node.encoded)
10005
10006
  return node.decoded.content
10006
10007
  }
10007
10008
 
@@ -909,7 +909,7 @@ class Peernet {
909
909
  return hash
910
910
  }
911
911
 
912
- async ls(hash) {
912
+ async ls(hash, options) {
913
913
  let data;
914
914
  const has = await dataStore.has(hash);
915
915
  if (has) data = await dataStore.get(hash);
@@ -921,17 +921,19 @@ class Peernet {
921
921
  for (const {path, hash} of node.decoded.links) {
922
922
  paths.push({path, hash});
923
923
  }
924
-
924
+ if (options?.pin) await dataStore.put(hash, node.encoded);
925
925
  return paths
926
926
  }
927
927
 
928
- async cat(hash) {
928
+ async cat(hash, options) {
929
929
  let data;
930
930
  const has = await dataStore.has(hash);
931
931
  if (has) data = await dataStore.get(hash);
932
932
  else data = await this.requestData(hash, 'data');
933
933
  const node = await new peernet.protos['peernet-file'](data);
934
+
934
935
  if (node.decoded?.links.length > 0) throw new Error(`${hash} is a directory`)
936
+ if (options?.pin) await dataStore.put(hash, node.encoded);
935
937
  return node.decoded.content
936
938
  }
937
939
 
@@ -882,7 +882,7 @@ class Peernet {
882
882
  return hash
883
883
  }
884
884
 
885
- async ls(hash) {
885
+ async ls(hash, options) {
886
886
  let data;
887
887
  const has = await dataStore.has(hash);
888
888
  if (has) data = await dataStore.get(hash);
@@ -894,17 +894,19 @@ class Peernet {
894
894
  for (const {path, hash} of node.decoded.links) {
895
895
  paths.push({path, hash});
896
896
  }
897
-
897
+ if (options?.pin) await dataStore.put(hash, node.encoded);
898
898
  return paths
899
899
  }
900
900
 
901
- async cat(hash) {
901
+ async cat(hash, options) {
902
902
  let data;
903
903
  const has = await dataStore.has(hash);
904
904
  if (has) data = await dataStore.get(hash);
905
905
  else data = await this.requestData(hash, 'data');
906
906
  const node = await new peernet.protos['peernet-file'](data);
907
+
907
908
  if (node.decoded?.links.length > 0) throw new Error(`${hash} is a directory`)
909
+ if (options?.pin) await dataStore.put(hash, node.encoded);
908
910
  return node.decoded.content
909
911
  }
910
912
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/peernet",
3
- "version": "0.13.3",
3
+ "version": "0.13.4",
4
4
  "description": "",
5
5
  "main": "dist/commonjs/peernet.js",
6
6
  "module": "src/module/peernet.js",
package/src/peernet.js CHANGED
@@ -570,7 +570,7 @@ export default class Peernet {
570
570
  return hash
571
571
  }
572
572
 
573
- async ls(hash) {
573
+ async ls(hash, options) {
574
574
  let data
575
575
  const has = await dataStore.has(hash)
576
576
  if (has) data = await dataStore.get(hash)
@@ -582,18 +582,19 @@ export default class Peernet {
582
582
  for (const {path, hash} of node.decoded.links) {
583
583
  paths.push({path, hash})
584
584
  }
585
-
585
+ if (options?.pin) await dataStore.put(hash, node.encoded)
586
586
  return paths
587
587
  }
588
588
 
589
- async cat(hash) {
589
+ async cat(hash, options) {
590
590
  let data
591
591
  const has = await dataStore.has(hash)
592
592
  if (has) data = await dataStore.get(hash)
593
593
  else data = await this.requestData(hash, 'data')
594
594
  const node = await new peernet.protos['peernet-file'](data)
595
- const paths = []
595
+
596
596
  if (node.decoded?.links.length > 0) throw new Error(`${hash} is a directory`)
597
+ if (options?.pin) await dataStore.put(hash, node.encoded)
597
598
  return node.decoded.content
598
599
  }
599
600