Diff
Not logged in

Differences From Artifact [f95f3c3a02]:

To Artifact [ba8b2a74b5]:


15
16
17
18
19
20
21




22
23
24
25
26

27

28
29
30
31
32
33
34
35
36
37
..
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
...
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118


119
120
121
122
123
124
125
...
147
148
149
150
151
152
153
154

155
156
157
158
159
class File {

  /**
  * @private
  **/
  constructor(ref) {
    this._ref = ref;




  }

  get ref() {
    const data = {
      created: this._ref.created,

      modified: this._ref.modified,

      size: this._ref.size,
      data_map_name: this._ref.data_map_name,
      user_metadata_ptr: this._ref.data_map_name.ref(),
      user_metadata_len: 0,
      user_metadata_cap: 0
    };

    if (this._ref.metadata) {
      let mData = this._ref.metadata;
      if (!isString(this._ref.metadata)) {
................................................................................
  }

  /**
  * When was this created? in UTC.
  * @return {Date}
  **/
  get created() {
    return nativeH.fromCTime(this._ref.created);
  }

  /**
  * When was this last modified? in UTC.
  * @return {Date}
  **/
  get modified() {
    return nativeH.fromCTime(this._ref.modified);
  }

  /**
  * How big is that file?
  * @return {Number} size in bytes
  **/
  get size() {
................................................................................
  * Create a new file with the given content, put the content
  * on the network via immutableData (public) and wrap it into
  * a File.
  * @param {(String|Buffer)} content
  * @returns {Promise<File>} a newly created file
  **/
  create(content) {
    const now = new Date();
    return this.mData.app.immutableData.create()
      .then((w) => w.write(content)
        .then(() => w.close()
          .then((xorAddr) => new File({
            size: content.length,
            data_map_name: xorAddr,
            created: nativeH.makeCTime(now),
            modified: nativeH.makeCTime(now)


          }))
        )
    );
  }

  /**
  * Find the file of the given filename (aka keyName in the MData)
................................................................................
  * @param {(String|Buffer)} fileName - the path to store the file under
  * @param {File} file - the file to serialise and store there
  * @param {Number} version - the current version number, to ensure you
           are overwriting the right one
  * @returns {Promise<File>} - the same file
  **/
  update(fileName, file, version) {
    return lib.file_update(this.mData.app.connection, this.mData.ref, fileName, file.ref, version)

      .then(() => file);
  }
}

module.exports = NFS;







>
>
>
>




|
>
|
>

|
|







 







|







|







 







|






|
|
>
>







 







|
>





15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
..
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
...
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
...
155
156
157
158
159
160
161
162
163
164
165
166
167
168
class File {

  /**
  * @private
  **/
  constructor(ref) {
    this._ref = ref;
    if (Array.isArray(ref.data_map_name)) {
      // translate the incoming array back into a buffer we can use internally
      this._ref.data_map_name = t.XOR_NAME(ref.data_map_name);
    }
  }

  get ref() {
    const data = {
      created_sec: this._ref.created_sec,
      created_nsec: this._ref.created_nsec,
      modified_sec: this._ref.modified_sec,
      modified_nsec: this._ref.modified_nsec,
      size: this._ref.size,
      data_map_name: this.dataMapName,
      user_metadata_ptr: this.dataMapName.ref(),
      user_metadata_len: 0,
      user_metadata_cap: 0
    };

    if (this._ref.metadata) {
      let mData = this._ref.metadata;
      if (!isString(this._ref.metadata)) {
................................................................................
  }

  /**
  * When was this created? in UTC.
  * @return {Date}
  **/
  get created() {
    return nativeH.fromSafeLibTime(this._ref.created_sec, this._ref.created_nsec);
  }

  /**
  * When was this last modified? in UTC.
  * @return {Date}
  **/
  get modified() {
    return nativeH.fromSafeLibTime(this._ref.modified_sec, this._ref.modified_nsec);
  }

  /**
  * How big is that file?
  * @return {Number} size in bytes
  **/
  get size() {
................................................................................
  * Create a new file with the given content, put the content
  * on the network via immutableData (public) and wrap it into
  * a File.
  * @param {(String|Buffer)} content
  * @returns {Promise<File>} a newly created file
  **/
  create(content) {
    const now = nativeH.toSafeLibTime(new Date());
    return this.mData.app.immutableData.create()
      .then((w) => w.write(content)
        .then(() => w.close()
          .then((xorAddr) => new File({
            size: content.length,
            data_map_name: xorAddr,
            created_sec: now.now_sec_part,
            created_nsec: now.now_nsec_part,
            modified_sec: now.now_sec_part,
            modified_nsec: now.now_nsec_part,
          }))
        )
    );
  }

  /**
  * Find the file of the given filename (aka keyName in the MData)
................................................................................
  * @param {(String|Buffer)} fileName - the path to store the file under
  * @param {File} file - the file to serialise and store there
  * @param {Number} version - the current version number, to ensure you
           are overwriting the right one
  * @returns {Promise<File>} - the same file
  **/
  update(fileName, file, version) {
    return lib.file_update(this.mData.app.connection, this.mData.ref, fileName,
                           file.ref.ref(), version)
      .then(() => file);
  }
}

module.exports = NFS;